package com.izhaowo.recommend.contrl;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.izhaowo.recommend.job.ListSortUtil;
import com.izhaowo.recommend.util.HBaseUtil;
import com.izhaowo.recommend.util.JavaDateUitl;
import com.izhaowo.recommend.util.MyUtils;
import com.izhaowo.recommend.vo.*;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.izhaowo.recommend.contrl.Result2Vo.getPointDistanceVO;
import static java.util.Objects.isNull;

/**
 * Created by HASEE on 2019/7/22.
 */
public class WeddingRecomPlanner {

    private static final Logger logger = LoggerFactory.getLogger(WeddingRecomPlanner.class);

    private static Map<String, String> provinceMap = new HashMap();

    static {
        provinceMap.put("001", "四川省");
        provinceMap.put("002", "江西省");
        provinceMap.put("003", "重庆市");
    }


    /**
     * 通用流程：推荐新人策划师—>邀约策划师->酒店策划师—>其他策划师
     * 南昌：推荐新人策划师—>南昌策划师—>邀约策划师->酒店策划师—>其他策划师
     *
     * @return
     */
    public static List<PlannerQueryInfoVO> queryWeddingRecomPlannerNew(String weddingId, String province, Integer inArea, String plannerTag) throws Exception {

        Thread.sleep(500);

        List<PlannerQueryInfoVO> resultList = new ArrayList<>();
        List<PlannerQueryInfoVO> resultList1 = new ArrayList<>();
        List<PlannerQueryInfoVO> resultList2 = new ArrayList<>();
        List<PlannerQueryInfoVO> resultList3 = new ArrayList<>();
        List<PlannerQueryInfoVO> resultList4 = new ArrayList<>();
        List<PlannerQueryInfoVO> resultList5 = new ArrayList<>();
        List<PlannerQueryInfoVO> rlist = new ArrayList<>();
        logger.info("___ wedding_id is " + weddingId + " , inArea is " + inArea + " , province is  " + province + " , " + provinceMap.get(province));
        UserWeddingVO wedding = RecommendWeddingPlanner.getUserWeddingById(weddingId); //   weddingId  为 RowKey
        if (isNull(wedding)) {
            throw new Exception("wedding_id is not exists");
        }

        if (province.length() > 3)
            provinceMap.putAll(RecommendWeddingPlanner.getProvinceMapById(province));

        // 查询婚礼筛选策划师标签
        WeddingUserTagVO tag = RecommendWeddingPlanner.queryWeddingUserTag(weddingId);   //   weddingId  为 RowKey
        String[] tagList = getTagList(tag);

        // 查询策划师排名
        List<PlannerRecomRankVO> allPlannerList = getAllWorkerRank(wedding.getBudgetMax(), inArea);

        List<PlannerRecomRankVO> plannerList = new ArrayList<>();
        Set<String> worker_idset = new HashSet<>();
        for (PlannerRecomRankVO plannerRecomRankVO : allPlannerList) {
            if (null != plannerRecomRankVO.getProvince() && provinceMap.get(province).equals(plannerRecomRankVO.getProvince())) {
                plannerList.add(plannerRecomRankVO);
                worker_idset.add(plannerRecomRankVO.getWorkerId());
            }
        }

        logger.info("___ first allPlannerSet size is " + worker_idset.size());
        logger.info("___ 从寇获取策划师 buffer is " + "[" + worker_idset.toString() + "]");

        String workerId = "";
        String weddingDate = wedding.getWeddingDate().replaceAll("-", "").substring(0, 8);

        if (inArea == 0 || inArea == 7) {
            // 第一步  查询推荐该用户的职业人
            //@TODO  部分字段找不到
            UserByCrmVO crmVO = RecommendWeddingPlanner.getUserByMsisdnV2(wedding.getContactsMsisdn());
            logger.info("_____ huidan  planner  crmVO msg is :  " + crmVO.getSecondChannelId());
            List<PlannerQueryInfoVO> result = new ArrayList<>();
            if (null != crmVO && crmVO.getId() != null && StringUtils.isNotBlank(crmVO.getSecondChannelId())) {
                workerId = RecommendWeddingPlanner.getWorkerIdByUserIdV3(crmVO.getSecondChannelId());
                if (inArea == 0) {
                    //判断推荐策划师
                    resultList = RecommandWorker.processRecomWorker(plannerList, workerId, weddingDate, "all");
                } else {
                    resultList = RecommandWorker.processRecomWorker(plannerList, workerId, weddingDate, "noMonth");
                    for (PlannerQueryInfoVO vo : resultList) {
                        if (vo.getCanOrder() > 0) {
                            result.add(vo);
                            logger.info("___ wedding_id is " + weddingId + " , getOrderReturnPlanner2  " + vo.getWorkerId() + " , " + vo.getName());
                        }
                    }
                }
            }
            if (inArea == 7) return result;
        }

        int responsize = 3;
        worker_idset.clear();
        if (resultList.size() > 0) {
            for (PlannerQueryInfoVO vo : resultList) {
                if (null != vo.getProvinceName() && provinceMap.get(province).equals(vo.getProvinceName())) {
                    responsize = 4;
                    resultList1.add(vo);
                    worker_idset.add(vo.getWorkerId());
                }
            }
        }

        logger.info("___ result1 size is " + worker_idset.size());
        if (worker_idset.size() > 0) {
            logger.info("___ 1.回单 planner buffer is " + "[" + worker_idset.toString() + "]");
        }

        Map<String, List<PlannerRecomRankVO>> recomRankMap = new HashMap<>();
        if (!isNull(plannerList) && plannerList.size() > 0) {
            List<WorkerQueryInfoVO> tempList = PlannerMsg.queryCanOrderPlanner(wedding.getWeddingDate().substring(0, 10), 1);
            List<WorkerQueryInfoVO> workersList = new ArrayList<>(200);
            for (WorkerQueryInfoVO vo : tempList) {
                workersList.add(vo);
            }

            // 获取策划师排名标签
            recomRankMap = plannerList.stream().collect(Collectors.groupingBy(PlannerRecomRankVO::getWorkerId));
            if (null != workersList && !workersList.isEmpty()) {
//                //如果推荐策划师在这个组合中，将其排除
                if (!isNull(workerId) && !"".equals(workerId)) {
                    for (int i = 0; i < workersList.size(); i++) {
                        WorkerQueryInfoVO worker = workersList.get(i);
                        if (worker.getId().equals(workerId)) {
                            workersList.remove(i);
                            break;
                        }
                    }
                }
                Gson gson = new Gson();
                logger.info("____ after dangqi xiandan  wedding_id is " + weddingId + " resultList1 size is " + resultList1.size() +
                        "weddingDate is " + weddingDate +
                        ", \thuidan " + gson.toJson(resultList1));

                logger.info("____ after dangqi xiandan  workersList size is " + workersList.size());
                worker_idset.clear();
                for (WorkerQueryInfoVO vo : workersList) {
                    worker_idset.add(vo.getId());
                }

                logger.info("___ 档期set size is " + worker_idset.size());
                if (worker_idset.size() > 0) {
                    logger.info("___ 2.档期 wedding_id is " + weddingId + " , inArea is " + inArea + "planner buffer is " + "[" + worker_idset.toString() + "]");
                }


                //查询所有符合条件的策划师  标签 、金额预算
                if (inArea < 8) {
                    resultList = getNormePlanner(resultList, workersList, recomRankMap, tagList, wedding.getBudgetMin(), wedding.getBudgetMax(),
                            inArea
                    );
                }

                logger.info("____ after biaoqian  yusuan , resultList size is " + resultList.size() +
                        "\twedding msg is " + gson.toJson(wedding));

                worker_idset.clear();
                for (PlannerQueryInfoVO vo : resultList) {
                    worker_idset.add(vo.getWorkerId());
                }
                logger.info("____ after biaoqian  yusuan , resultList size is " + worker_idset.size() +
                        "\t  worker_idset   is " + worker_idset.toString());

//                Map<String, PlannerQueryInfoVO> workerPlannerVO =
//                        resultList.stream()
//                                .collect(Collectors.toMap(PlannerQueryInfoVO::getWorkerId, bs -> {
//                                    return bs;
//                                }));
//                if (null != workerId && workerId.length() > 0 && workerPlannerVO.containsKey(workerId)) {
//                    responsize = 4;
//                    resultList1.add(workerPlannerVO.get(workerId));
//                }

                //南充市先推荐南昌策划师
//                if ("南充市".equals(wedding.getCityName())) {
//                    if (!isNull(resultList) && resultList.size() > 0) {
//                        for (PlannerQueryInfoVO info : resultList) {
//                            if ("南充市".equals(info.getCityName()) && !JSON.toJSONString(resultList1).contains(info.getWorkerId())) {
//                                if (resultList1.size() < responsize) {
//                                    resultList1.add(info);
//                                }
//                                logger.info("____ after nanchong city wedding_id is " + weddingId + " resultList1 size is " + resultList1.size() +
//                                                "\tweddingDate is " + weddingDate + "info.getWorkerId is " + info.getWorkerId() +
//                                                " , resultList1 msg is " + gson.toJson(resultList1)
//
//                                );
//                            }
//                        }
//                    }
//                }
                worker_idset.clear();
                for (PlannerQueryInfoVO vo : resultList1) {
                    worker_idset.add(vo.getWorkerId());
                }

                logger.info("___ 南充set size is " + worker_idset.size());
                if (worker_idset.size() > 0) {
                    logger.info("___ 3.南充 planner buffer is " + "[" + worker_idset.toString() + "]");
                }

                resultList4.addAll(resultList1);
//                resultList5.addAll(resultList1);
                //第二步 判断预约时推荐的策划师
                if (inArea == 0 && resultList1.size() < responsize) {
                    List<PlannerRecomRecordVO> newWeddingRecomList = getRecomPlanner(wedding, workerId);
                    if (newWeddingRecomList.size() > 0) {
                        resultList2 = processReviseRecomWorker(resultList4, newWeddingRecomList, workersList, recomRankMap, tagList, wedding,
                                (responsize - resultList1.size()), null, inArea);
                        logger.info("____ yuyue planner wedding_id is " + weddingId + " , inArea is " + inArea + " resultList2 size is " + resultList2.size() +
                                        "\tweddingDate is " + weddingDate + "CityName is " + wedding.getCityName() +
                                        " resultList2 msg is  " + gson.toJson(resultList2)
                                // 预约策划师有了，不再用stringbuffer打印。
                        );
                    }
                }
                if (resultList2.size() > 0) {
                    for (PlannerQueryInfoVO vo : resultList2) {
                        if (null != vo.getProvinceName() && provinceMap.get(province).equals(vo.getProvinceName())) {
                            resultList5.add(vo);
                            resultList4.add(vo);
                        }
                    }
                }

                //第三步 获取酒店推荐数据
                if (inArea < 8 && resultList4.size() < responsize) {
                    //2019-04-17根据酒店&预算获取对应的策划师
                    resultList3 = processHotelRecomWorker(wedding.getBudgetMax(), wedding.getHotel(), wedding.getProvinceName(), wedding.getCityName(),
                            wedding.getHotelId(), workersList, resultList4, plannerList, recomRankMap, tagList, (responsize - resultList4.size()),
                            weddingDate, wedding.getHotelId(), provinceMap.get(province), inArea);
//                    resultList3 = processHotelRecomWorker(wedding.getBudgetMax(), wedding.getHotel(), wedding.getProvinceName(), wedding.getCityName(),
//                            wedding.getHotelId(), resultList, resultList4, plannerList, recomRankMap, tagList, (responsize - resultList4.size()),
//                            weddingDate, wedding.getHotelId());
                    logger.info("____ jiudian planner wedding_id is " + weddingId + " , inArea is " + inArea + " resultList3 size is " + resultList3.size() +
                                    "\twedding msg is " + gson.toJson(wedding) +
                                    " resultList3 msg is " + gson.toJson(resultList3)
                    );
                }

                worker_idset.clear();
                for (PlannerQueryInfoVO vo : resultList3) {
                    worker_idset.add(vo.getWorkerId());
                }

//                StringBuffer jiudianBuff = new StringBuffer();
//                for (String planner : jiudianSet) {
//                    jiudianBuff.append(planner + ",");
//                }
                logger.info("___ 酒店set size is " + worker_idset.size());
                if (worker_idset.size() > 0) {
                    logger.info("___ 4.酒店 planner buffer is " + "[" + worker_idset.toString() + "]");
                }
                // check planner tags and region
                if (inArea >= 8) {
                    resultList3 = queryJJPlanner(wedding.getBudgetMax(), inArea, tagList, workersList, plannerList);
                }

                // 再次对省份进行限定。
                if (resultList3.size() > 0) {
                    for (PlannerQueryInfoVO vo : resultList3) {
                        if (null != vo.getProvinceName() && provinceMap.get(province).equals(vo.getProvinceName())) {
                            resultList5.add(vo);
                            resultList4.add(vo);
                        }
                    }
                }

//                resultList5.addAll(resultList3);
//                resultList4.addAll(resultList3);
                //2019-07-08 如果酒店匹配结果不为0，就结束
//                if (resultList3.size() == 0) { // 补充策划师
//                    //第四步 剩余策划师判断
//                    if (resultList4.size() < responsize) {
//                        for (PlannerQueryInfoVO info : resultList) {
//                            if (!JSON.toJSONString(resultList4).contains(info.getWorkerId())) {
//                                if (resultList4.size() < responsize && null != info.getProvinceName()
//                                        && provinceMap.get(province).equals(info.getProvinceName())
////                                        wedding.getProvinceName().equals(info.getProvinceName())
//                                        ) {
//                                    resultList4.add(info);
//                                    resultList5.add(info);
//                                }
//                            }
//                        }
//                        logger.info("____ other planner wedding_id is " + weddingId + " resultList5 size is " + resultList5.size() +
//                                "resultList5 is " + gson.toJson(resultList5));
//                    }
//                }
            } else {
                logger.info("___ wedding_id is " + weddingId + ", filter with dangqi xiandan workersList  is empty");
            }
            if (resultList5.size() > 0) {
                // 剩余职业人排序
                ListSortUtil<PlannerQueryInfoVO> sortList = new ListSortUtil<PlannerQueryInfoVO>();
                sortList.sortByMethod(resultList5, "getSot", true);
            }
            resultList1.addAll(resultList5);
        } else {
            logger.info("___ wedding_id is " + weddingId + " ,and kouyao laoshi planner list is empty");
        }

        worker_idset.clear();
        for (PlannerQueryInfoVO vo : resultList5) {
            worker_idset.add(vo.getWorkerId());
        }
//        StringBuffer buchongbuff = new StringBuffer();
//        for (String planner : buchongSet) {
//            buchongbuff.append(planner + ",");
//        }
        logger.info("___ 补充set size is " + worker_idset.size());
        if (worker_idset.size() > 0) {
            logger.info("___ 5.补充 planner buffer is " + "[" + worker_idset.toString() + "]");
        }

        if (resultList1.size() > 0) {
            for (PlannerQueryInfoVO info : resultList1) {
                if (info.getDistance() == 0) {
                    String distanceStr = getDistance(info.getWorkerId(), weddingId);
                    if (distanceStr.contains(":")) {
                        String[] d = distanceStr.split(":");
                        info.setDistance(Double.valueOf(d[1]));
                        info.setDistanceStr(distanceStr + "km");
                    } else {
                        info.setDistanceStr(distanceStr);
                    }
                } else {
                    double distance =
                            new BigDecimal(info.getDistance()).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    String distanceStr = "距酒店:" + distance + "km";
                    info.setDistanceStr(distanceStr);
                }
                rlist.add(info);
            }
        }
        return rlist;
    }


    public static List<PlannerQueryInfoVO> queryWeddingRecomPlannerYingJing(Integer budget, String hotelId,
                                                                            String scheduleDay, String plannerTag,
                                                                            String nature) throws Exception {
        List<PlannerQueryInfoVO> resultList3 = new ArrayList<>();

        logger.info("___ yingjing query budget is " + budget + " scheduleDay is " + scheduleDay +
                " , hotelId " + hotelId + " , nature is " + nature + " , plannerTag is  " + plannerTag);
        // 查询策划师排名
        List<PlannerRecomRankVO> allPlannerList = getAllWorkerRank(budget * 100, 0);
        logger.info("___ plananer yingjing allPlannerList  is " + allPlannerList.size());

        List<PlannerRecomRankVO> plannerList = new ArrayList<>();
        Set<String> worker_idset = new HashSet<>();
        for (PlannerRecomRankVO plannerRecomRankVO : allPlannerList) {
            if (null != plannerRecomRankVO.getProvince() && provinceMap.get("001").equals(plannerRecomRankVO.getProvince())) {
                plannerList.add(plannerRecomRankVO);
                worker_idset.add(plannerRecomRankVO.getWorkerId());
            }
        }

        Map<String, List<PlannerRecomRankVO>> recomRankMap = plannerList.stream().collect(Collectors.groupingBy(PlannerRecomRankVO::getWorkerId));
        if (!isNull(plannerList) && plannerList.size() > 0) {

            plannerList = getTagPlanners(plannerList, plannerTag);
            List<WorkerQueryInfoVO> recomendPlanners = getScheduleDayPlanners(plannerList, scheduleDay);

            recomendPlanners = getSectionPlanners(recomendPlanners, budget);
            Map<String, Double> workerDis = new HashMap<>();

            recomendPlanners = getDistancePlanners(recomendPlanners, hotelId, workerDis);

            resultList3 = processHotelRecomWorkerYingJing(recomendPlanners, workerDis, recomRankMap, 20);

            resultList3 = getPlannerPersonality(resultList3, nature);

//            if (resultList3.size() > 0) {
//                for (PlannerQueryInfoVO info : resultList3) {
//                    if (info.getDistance() == 0) {
//                        String distanceStr = getDistance(info.getWorkerId(), weddingId);
//                        if (distanceStr.contains(":")) {
//                            String[] d = distanceStr.split(":");
//                            info.setDistance(Double.valueOf(d[1]));
//                            info.setDistanceStr(distanceStr + "km");
//                        } else {
//                            info.setDistanceStr(distanceStr);
//                        }
//                    } else {
//                        double distance =
//                                new BigDecimal(info.getDistance()).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//                        String distanceStr = "距酒店:" + distance + "km";
//                        info.setDistanceStr(distanceStr);
//                    }
//                    rlist.add(info);
//                }
//            }

        }


        return resultList3;
    }

    public static List<WorkerQueryInfoVO> getScheduleDayPlanners(List<PlannerRecomRankVO> plannerList, String scheduleDay) {
        Integer flag = 1;
        if (StringUtils.isBlank(scheduleDay)) {
//            return plannerList;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            scheduleDay = sdf.format(new Date());
            flag = 2;
        }
        List<WorkerQueryInfoVO> tempList = PlannerMsg.queryCanOrderPlanner(scheduleDay.substring(0, 10), flag);
        List<WorkerQueryInfoVO> workersList = new ArrayList<>(200);
        for (WorkerQueryInfoVO vo : tempList) {
            workersList.add(vo);
        }
        List<WorkerQueryInfoVO> temp = new ArrayList<>();
        Map<String, List<WorkerQueryInfoVO>> schedulePlannerMap = workersList.stream().collect(Collectors.groupingBy(WorkerQueryInfoVO::getId));
        for (PlannerRecomRankVO vo : plannerList) {
            if (schedulePlannerMap.containsKey(vo.getWorkerId())) {
                List<WorkerQueryInfoVO> tempL = schedulePlannerMap.get(vo.getWorkerId());
                if (null != tempL && tempL.size() > 0 && tempL.get(0).getCityName().equals("成都市"))
                    temp.addAll(schedulePlannerMap.get(vo.getWorkerId()));
            }
        }
        logger.info("___ plananer yingjing scheduleDay  is " + temp.size());
        return temp;
    }

    public static List<WorkerQueryInfoVO> getDistancePlanners(List<WorkerQueryInfoVO> plannerList, String hotelId, Map<String, Double> workerDis) {
        if (StringUtils.isBlank(hotelId)) {
            return plannerList;
        }

        List<HotelPlannerRecomRankVO> hotelPlannerList = getHotelSectionPlannerYingJing(0, hotelId);

        List<WorkerQueryInfoVO> temp = new ArrayList<>();
        Map<String, List<HotelPlannerRecomRankVO>> schedulePlannerMap = hotelPlannerList.stream().collect(Collectors.groupingBy(HotelPlannerRecomRankVO::getId));
        for (WorkerQueryInfoVO vo : plannerList) {
            if (schedulePlannerMap.containsKey(vo.getId())) {
                List<HotelPlannerRecomRankVO> workerHotel = schedulePlannerMap.get(vo.getId());
                if (null != workerHotel && workerHotel.size() > 0) {
                    workerDis.put(vo.getId(), Double.valueOf(workerHotel.get(0).getDistance()));
                }
                temp.add(vo);
            }
        }
        logger.info("___ plananer yingjing hotelId  is " + temp.size());

        return temp;
    }

    public static List<PlannerQueryInfoVO> getPlannerPersonality(List<PlannerQueryInfoVO> plannerList, String nature) {
        if (StringUtils.isBlank(nature)) {
            return plannerList;
        }

        List<YingjingPlannerPersonalityVO> personalityVOs = RecommendWeddingPlanner.getYingJingPlannerPersonality(null);
        Map<String, List<YingjingPlannerPersonalityVO>> personalityVOsMap = personalityVOs.stream().collect(Collectors.groupingBy(YingjingPlannerPersonalityVO::getPlanner_id));
        ListSortUtil<YingjingPlannerPersonalityVO> sortList = new ListSortUtil<YingjingPlannerPersonalityVO>();
        String sotFiled = "get" + nature;
        sortList.sortByMethod(personalityVOs, sotFiled, true);
        List<PlannerQueryInfoVO> temp = new ArrayList<>();
        for (PlannerQueryInfoVO vo : plannerList) {
            if (personalityVOsMap.containsKey(vo.getWorkerId()))
                temp.add(vo);
        }
        List<PlannerQueryInfoVO> temp2 = new ArrayList<>();
        Map<String, List<PlannerQueryInfoVO>> tempMap = temp.stream().collect(Collectors.groupingBy(PlannerQueryInfoVO::getWorkerId));
        for (YingjingPlannerPersonalityVO vo : personalityVOs) { // 按照 性格排序
            if (tempMap.containsKey(vo.getPlanner_id()))
                temp2.addAll(tempMap.get(vo.getPlanner_id()));
        }

        logger.info("___ plananer yingjing hotelId  is " + temp2.size());

        return temp2;
    }

    public static List<WorkerQueryInfoVO> getSectionPlanners(List<WorkerQueryInfoVO> plannerList, Integer budget) {
        if (null == budget || 0 == budget) {
            return plannerList;
        }

        List<YingjingPlannerSectionVO> sectionVOs = RecommendWeddingPlanner.getYingJingPlannerSection(HBaseUtil.getTalkOrderFilter("", "成都市"));
        Map<String, List<YingjingPlannerSectionVO>> sectionVOsMap = sectionVOs.stream().collect(Collectors.groupingBy(YingjingPlannerSectionVO::getPlanner_id));
        int region = getSectionByMarketBudget(budget * 100, 0);

        List<WorkerQueryInfoVO> temp = new ArrayList<>();
        for (WorkerQueryInfoVO vo : plannerList) {
            WorkerQueryInfoVO tempVo = getSectionVOYingJingV2(region, vo, sectionVOsMap);
            if (tempVo != null)
                temp.add(vo);
        }
        logger.info("___ plananer yingjing budget  is " + temp.size());
        return temp;
    }


    public static List<PlannerRecomRankVO> getTagPlanners(List<PlannerRecomRankVO> plannerList, String plannerTag) {
        if (StringUtils.isBlank(plannerTag)) {
            return plannerList;
        }
        List<String> tempTags = new ArrayList<>();

        if (plannerTag.contains(",")) {
            String[] tagsArr = plannerTag.split(",");
            for (String tag : tagsArr) {
                tempTags.add(tag);
            }
        } else {
            tempTags.add(plannerTag);
        }

        List<PlannerRecomRankVO> temp = new ArrayList<>();
        for (PlannerRecomRankVO vo : plannerList) {
            if (null != vo.getTags() && vo.getTags().containsAll(tempTags))
                temp.add(vo);
        }
        logger.info("___ plananer yingjing plannerTag  is " + temp.size());
        return temp;
    }


    /**
     * check budget tag and schedule
     *
     * @param budgetMax
     * @param inArea
     * @param tagList
     * @param workersList
     * @param plannerList
     * @return
     */
    public static List<PlannerQueryInfoVO> queryJJPlanner(Integer budgetMax, Integer inArea, String[] tagList,
                                                          List<WorkerQueryInfoVO> workersList,
                                                          List<PlannerRecomRankVO> plannerList) {
        logger.info("_____  JJPlanner: is " + budgetMax + " tagList is   " + tagList.length +
                " , workersList size " + workersList.size() + " , plannerList size " + plannerList.size());
        List<PlannerQueryInfoVO> rlist = new ArrayList<>();
        int section = getSectionByMarketBudget(budgetMax, inArea);   //use budget  the section of area
        List<PlannerRecomRankVO> temp = new ArrayList<>();
        for (PlannerRecomRankVO vo : plannerList) {
            if (Double.valueOf(vo.getSection()).equals(Double.valueOf(String.valueOf(section))))
                temp.add(vo);
        }

        if (temp.size() > 0) {
            if (!isNull(workersList) && workersList.size() > 0) {
                Map<String, WorkerQueryInfoVO> workerMap = workersList.stream()
                        .collect(Collectors.toMap(WorkerQueryInfoVO::getId, bs -> {
                            return bs;
                        }));

                Gson gson = new Gson();
                ListSortUtil<PlannerRecomRankVO> sortList = new ListSortUtil<PlannerRecomRankVO>();
                sortList.sortByMethod(temp, "getSot", true);

                logger.info("_____  JJ market " + " hotelPlannerList  sort msg is  " + gson.toJson(temp));

                for (PlannerRecomRankVO vo : temp) {
                    WorkerQueryInfoVO worker = workerMap.get(vo.getWorkerId());
                    if (null != worker) {
                        boolean tagFlag = veritfyTagV2(tagList, vo.getTags());
                        if (tagFlag) {
                            // 职业人通过筛选
                            PlannerQueryInfoVO info = new PlannerQueryInfoVO();
                            BeanUtils.copyProperties(worker, info);
                            // 推荐信息合并
                            info.setWorkerId(vo.getWorkerId());
                            info.setCaseRate(vo.getCaseRate());
                            info.setReorderRate(vo.getReorderRate());
                            info.setPreSpeScore(vo.getPreSpeScore());
                            info.setAllScoreFinal(vo.getAllScoreFinal());
                            info.setSot(vo.getSot());
                            info.setScoreFlag1(vo.getScoreFlag1());
                            info.setScoreFlag2(vo.getScoreFlag2());
                            info.setScoreFlag3(vo.getScoreFlag3());
                            info.setScoreFlag4(vo.getScoreFlag4());
                            info.setScoreFlag5(vo.getScoreFlag5());
                            info.setTagList(vo.getTags());
                            info.setServiceCity(null);
                            info.setProfile(null);
                            info.setHomePage(null);
                            info.setType(0);
                            info.setHotelScore(vo.getSot());
//                        info.setDistance(vo.getDistance());
                            rlist.add(info);
                            if (rlist.size() >= 3) break;
                        }
                    }
                }
            }
        }

        return rlist;
    }


    public static List<PlannerQueryInfoVO> getOrderReturnPlanner(String weddingId, String typeStr) {
        logger.info("___ wedding_id is " + weddingId);
        UserWeddingVO wedding = RecommendWeddingPlanner.getUserWeddingById(weddingId); //   weddingId  为 RowKey
        if (isNull(wedding)) {
            logger.info("___ wedding_id is " + weddingId + " ,is not exists ");
            return new ArrayList<>();
        }
        UserByCrmVO crmVO = RecommendWeddingPlanner.getUserByMsisdnV2(wedding.getContactsMsisdn());
        logger.info("_____ getOrderReturnPlanner  planner  crmVO msg is :  " + crmVO.getSecondChannelId());
        if (null != crmVO && crmVO.getId() != null && StringUtils.isNotBlank(crmVO.getSecondChannelId())) {
            String workerId = RecommendWeddingPlanner.getWorkerIdByUserIdV3(crmVO.getSecondChannelId());
            //判断推荐策划师
            String weddingDate = wedding.getWeddingDate().replaceAll("-", "").substring(0, 8);
            List<PlannerQueryInfoVO> temp = RecommandWorker.processRecomWorker(null, workerId, weddingDate, typeStr);
            List<PlannerQueryInfoVO> result = new ArrayList<>();
            for (PlannerQueryInfoVO vo : temp) {
                if (vo.getCanOrder() > 0) {
                    result.add(vo);
                    logger.info("___ wedding_id is " + weddingId + " , getOrderReturnPlanner  " + vo.getWorkerId() + " , " + vo.getName());
                }
            }
//            List<WorkerQueryInfoVO> workerQueryInfoVOList = PlannerMsg.queryCanOrderPlanner(wedding.getWeddingDate().substring(0, 10), 1);
            return result;
        }
        return new ArrayList<>();
    }


    public static void saveRecomResult_v3(String wedding_id, String province, Integer inArea,
                                          String startTime, List<PlannerQueryInfoVO> result,
                                          String plannerTag) {
        try {
            UserWeddingVO wedding = RecommendWeddingPlanner.getUserWeddingById(wedding_id);
            StringBuffer sb = new StringBuffer();
            sb.append(startTime.substring(0, 8));
            String rowkey = sb.reverse() + "=" + wedding_id + "=" + inArea + "=" + startTime.substring(8);
            Put put = new Put(Bytes.toBytes(rowkey));
            Map recom = new HashMap<String, String>();
            if (!result.isEmpty() && result.size() > 0) {
                for (PlannerQueryInfoVO vo : result) {
                    recom.put(vo.getWorkerId(), vo.getName());
                }
            }

            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("wedding_id"), Bytes.toBytes(wedding_id));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("provinceId"), Bytes.toBytes(province));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("startTime"), Bytes.toBytes(startTime));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("inArea"), Bytes.toBytes(inArea));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("plannerTag"), Bytes.toBytes(plannerTag));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("recom"), Bytes.toBytes(recom.toString()));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("province"), Bytes.toBytes(provinceMap.get(province)));

            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("budgetMax"), Bytes.toBytes(wedding.getBudgetMax()));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("cityId"), Bytes.toBytes(wedding.getCityId()));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("cityName"), Bytes.toBytes(wedding.getCityName()));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("hotel"), Bytes.toBytes(wedding.getHotel()));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("weddingDate"), Bytes.toBytes(wedding.getWeddingDate()));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("hotelId"), Bytes.toBytes(wedding.getHotelId()));

            List<Put> list = new ArrayList<Put>();
            list.add(put);
            HBaseUtil.put("recom_planner_result_v3", list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static List<PlannerRecomRankVO> getAllWorkerRank(int budget, int inArea) {
        List<PlannerRecomRankVO> allPlannerList = null;
        if (inArea >= 8) {
            allPlannerList = RecommendWeddingPlanner.queryPlannerRecomRankJJ(inArea);
        } else {
            if (budget > 5000000) {
                allPlannerList = RecommendWeddingPlanner.queryHighPlannerRecomRank();
                logger.info("_______ query high budget  all planner list is  " + allPlannerList.size());
            } else {
                allPlannerList = RecommendWeddingPlanner.queryPlannerRecomRankVersion2();
                logger.info("_______ query  low budget  all planner list is  " + allPlannerList.size());
            }
        }

        return allPlannerList;
    }

    public static String[] getTagList(WeddingUserTagVO tag) {
        String[] tagList = null;
        if (!isNull(tag)) {
            if (!"".equals(tag.getTag1()) && !"".equals(tag.getTag2())) {
                tagList = new String[2];
                tagList[0] = tag.getTag1();
                tagList[1] = tag.getTag2();
            }
            if (!"".equals(tag.getTag1()) && "".equals(tag.getTag2())) {
                tagList = new String[1];
                tagList[0] = tag.getTag1();
            }
            if ("".equals(tag.getTag1()) && !"".equals(tag.getTag2())) {
                tagList = new String[1];
                tagList[0] = tag.getTag2();
            }
            if ("".equals(tag.getTag1()) && "".equals(tag.getTag2())) {
                tagList = new String[0];
            }
        }
        return tagList;
    }


    public static List<TalkOrderPlannerVO> getTalkOrderPlanner(Integer budget,
                                                               String tags,
                                                               String province,
                                                               String scheduleDay,
                                                               String weddingDate) {
        logger.info("___ talk order msg: budget is " + budget + " , tags is " + tags +
                " , province is " + province + " , scheduleDay is " + scheduleDay + " weddingDate is " + weddingDate);
//        List<TalkOrderPlannerVO> result = new ArrayList<>(3);
        List<TalkOrderPlannerVO> result = new ArrayList<>();
        int section = getSectionByMarketBudget(budget * 100, 0);
        List<TalkOrderPlannerVO> talkOrderPlannerVOList = RecommendWeddingPlanner.getTalkOrderPlanners(HBaseUtil.getTalkOrderFilter(String.valueOf(section), "成都市"));
        if (null != talkOrderPlannerVOList && !talkOrderPlannerVOList.isEmpty()) {
            Gson gson = new Gson();
            StringBuilder sb = new StringBuilder();
            for (TalkOrderPlannerVO vo : talkOrderPlannerVOList) {
                sb.append(vo.getPlanner_id()).append(",");
            }
            logger.info("___ talkOrderPlannerVOList " + sb.toString());
//            scheduleDay = scheduleDay.replaceAll("[- :]", "").substring(0, 8);
//            List<WorkerQueryInfoVO> workerQueryInfoVOList = WeddingRecomPlanner.getServiceWorker(scheduleDay, null, null, null, -1, -1);
            List<WorkerQueryInfoVO> workerQueryInfoVOList = PlannerMsg.queryCanOrderPlanner(scheduleDay.substring(0, 10), 2);
            sb = new StringBuilder();
            for (WorkerQueryInfoVO vo : workerQueryInfoVOList) {
                sb.append(vo.getId()).append(",");
            }
            logger.info("___ talk order meeting date worker dangqi  " + sb.toString());
            logger.info("___ talk order meeting date worker dangqi list size " + workerQueryInfoVOList.size());

            List<WorkerQueryInfoVO> workerQueryInfoVOWeddingDateList = null;
            if (StringUtils.isEmpty(weddingDate) || "\"\"".equals(weddingDate) || "null".equals(weddingDate)) {
//                weddingDate = scheduleDay;
                workerQueryInfoVOWeddingDateList = workerQueryInfoVOList;
            } else {
                workerQueryInfoVOWeddingDateList = PlannerMsg.queryCanOrderPlanner(weddingDate.substring(0, 10), 1);
            }

//            List<WorkerQueryInfoVO> workerQueryInfoVOWeddingDateList = PlannerMsg.queryCanOrderPlanner(weddingDate.substring(0, 10), 1);
            sb = new StringBuilder();
            for (WorkerQueryInfoVO vo : workerQueryInfoVOWeddingDateList) {
                sb.append(vo.getId()).append(",");
            }
            logger.info("___ talk order wedding date worker dangqi  " + sb.toString());

            Map<String, List<String>> workerTags = RecommendWeddingPlanner.queryPlannerWeddingTag();
            Map<String, List<WorkerQueryInfoVO>> workerInfoMap = workerQueryInfoVOList.stream().collect(Collectors.groupingBy(WorkerQueryInfoVO::getId));
            Map<String, List<WorkerQueryInfoVO>> workerInfoWeddingDateMap = workerQueryInfoVOWeddingDateList.stream().collect(Collectors.groupingBy(WorkerQueryInfoVO::getId));
            for (TalkOrderPlannerVO talkOrderPlannerVO : talkOrderPlannerVOList) {
                boolean flag = false;
                String plannerId = talkOrderPlannerVO.getPlanner_id();
                if (workerInfoMap.containsKey(plannerId) && workerInfoWeddingDateMap.containsKey(plannerId)) {
                    if (plannerId.equals("edf1c9d6-5165-4a87-9543-aa9d09a8db90")) {
                        System.out.println("  ni daye ");
                    }
                    WorkerQueryInfoVO meetingDayVo = workerInfoMap.get(plannerId).get(0);
                    if (meetingDayVo.getSchedule() == 1 || meetingDayVo.getOrders() > 0)
                        flag = true;
                    talkOrderPlannerVO.setHasWedding(meetingDayVo.getOrders());
//                    if (meetingDayVo.getOrders() > 0) {
//                        talkOrderPlannerVO.setHasWedding(meetingDayVo.getOrders());
//                    } else {
//                        talkOrderPlannerVO.setHasWedding(0);
//                    }
                }
                if (flag && !"\"\"".equals(tags) && !"\"".equals(tags) && StringUtils.isNotEmpty(tags.trim()) && null != tags && tags.length() > 0) {
                    if (workerTags.containsKey(plannerId)) {
                        List<String> tempTagList = workerTags.get(plannerId);
                        if (tags.contains(",")) {
                            String[] tagArr = tags.split(",");
                            boolean tempFlag = true;
                            for (String tag : tagArr) {
                                if (!tempTagList.contains(tag)) {
                                    tempFlag = false;
                                    break;
                                }
                            }
                            flag = flag && tempFlag;
                        } else {
                            flag = tempTagList.contains(tags);
                        }
                    } else {
                        flag = false;
                    }
                }
//                if (flag && null != province && province.length() > 0) {
//                    if (talkOrderPlannerVO.getProvince().equals(province)) {
//                        flag = true;
//                    } else {
//                        flag = false;
//                    }
//                }

//                if (flag && talkOrderPlannerVO.getCity().equals("成都市")) {
//                    flag = true;
//                } else {
//                    flag = false;
//                }

//                if (flag && result.size() < 3) {
                if (flag) {
                    String userId = workerInfoMap.get(plannerId).get(0).getUserId();
                    talkOrderPlannerVO.setUserId(userId);
                    result.add(talkOrderPlannerVO);
                }

//                if (result.size() >= 3) break;
            }
            logger.info("___ talk order worker  result" + gson.toJson(result));
        }
        if (!result.isEmpty()) {
            ListSortUtil<TalkOrderPlannerVO> sortList = new ListSortUtil<TalkOrderPlannerVO>();
            sortList.sortByMethod(result, "getAll_score_final", true);
        }

        return result;
    }


    public static String getDistance(String workerId, String weddingId) {
        //计算距离
        String str = "无法获取距离";
        //查询职业人
        WorkerVO worker = RecommendWeddingPlanner.getWorkerVOById(workerId);
        if (!isNull(worker)) {
            try {
                List<PointDistanceVO> lists = getWeddingDistance(weddingId, worker);
                if (!isNull(lists) && !isNull(lists.get(0)) && !isNull(lists.get(0).getDistance())) {
//                    double distance = new BigDecimal((float) lists.get(0).getDistance() / 1000).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    double distance =
                            new BigDecimal(lists.get(0).getDistance()).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    str = "距酒店:" + distance;
                } else {
                    str = "无法获取距离";
                }
            } catch (Exception e) {
                if (JSON.toJSONString(e).contains("酒店")) {
                    str = "无法获取酒店地址";
                } else if (JSON.toJSONString(e).contains("常驻地")) {
                    str = "暂无职业人地址";
                } else {
                    str = "无法获取距离";
                }
            }
        } else {
            str = "无法获取距离";
        }
        return str;
    }

    public static List<PointDistanceVO> getWeddingDistance(String weddingId, WorkerVO worker) {
//		//查询婚礼远程服务费模板
//		UserWeddingVO wedding = userWeddingControllerService.queryUserWeddingById(weddingId);
//		assertNull(wedding,"用户婚礼信息不存在");
//		WeddingBrokerSimpleVO broker = weddingBrokerController.queryWeddingBrokerById(wedding.getBrokerId());
//		assertNull(broker,"经纪人婚礼信息不存在");
//		HotelVO hotelVO = weddingHotelControllerService.queryHotelVOById(wedding.getHotelId());
//		assertNull(hotelVO,"酒店信息不存在");
//		//查询省份经纬度
//		RemoteServiceFeeOriginVO origin = queryRemoteServiceFeeOriginVO(broker.getProvinceId());
//		assertNull(origin,"省份基准经纬度信息不存在");
//
//        //2019-06-10 计算方式按酒店和职业人距离
//        //查询婚礼远程服务费模板
//        UserWeddingVO wedding = RecommendWeddingPlanner.getUserWeddingById(weddingId);
////        assertNull(wedding, "用户婚礼信息不存在");
////        assertNull(wedding.getHotelId(), "用户婚礼酒店信息不存在");
//        HotelVO hotelVO = RecommendWeddingPlanner.queryHotelVOById(wedding.getHotelId());
////        assertNull(hotelVO, "酒店信息不存在");
//        //查询职业人常驻地址
////        assertNull(worker.getAddressId(), "职业人常驻地址不存在");
//        HotelVO address = RecommendWeddingPlanner.queryHotelVOById(worker.getAddressId());
////        assertNull(address, "职业人常驻地址不存在");
//        //计算距离
//        LineDistanceQueryRequestBean bean = new LineDistanceQueryRequestBean();
//        //目的地(酒店)
//        GeographyPoint gp = new GeographyPoint();
//        gp.setLatitude(hotelVO.getLatitude());
//        gp.setLongitude(hotelVO.getLongitude());
//        bean.setDestinationPoint(gp);
//
//        //出发地
//        List<GeographyPoint> list = new ArrayList<>();
//        GeographyPoint gp1 = new GeographyPoint();
//        gp1.setLatitude(address.getLatitude());
//        gp1.setLongitude(address.getLongitude());
//        list.add(gp1);
//        bean.setOriginsPoints(list);
////        List<PointDistanceVO> lists = geographyControllerService.queryLineDistance(bean);
//        //@TODO over。
        String workerId = worker.getId();
        Result r = HBaseUtil.getRow("v2_rp_tb_user_wedding", Bytes.toBytes(weddingId));
        String hotelId = Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("hotel_id")));
//        String rowkey = String.valueOf(MakeHashRow.hashCode(hotelId + ":" + workerId));
        Result res = HBaseUtil.getRow("v2_rp_workers_hotel_distance", Bytes.toBytes(hotelId + ":" + workerId));
        List<PointDistanceVO> lists = new ArrayList<>();
        try {
            PointDistanceVO vo = getPointDistanceVO(res);
            lists.add(vo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lists;
    }

    private static String getVocationId() {
        List<VocationVO> vocationList = RecommendWeddingPlanner.getVocations();
        String vocationId = null;
        if (!isNull(vocationList) && vocationList.size() > 0) {
            for (VocationVO vocation : vocationList) {
                if ("策划师".equals(vocation.getName())) {
                    vocationId = vocation.getId();
                }
            }
        }
//        return vocationId;
        return "d677824c-bae7-11e7-99f0-408d5c0cd580";
    }

    public static int getSectionByMarketBudget(int budgetMax, int inArea) {
        int region = 0;
        if (budgetMax > 0 && budgetMax <= 1200000) {
            region = 1;
        }
        if (budgetMax > 1200000 && budgetMax <= 1800000) {
            region = 2;
        }
        if (budgetMax > 1800000 && budgetMax <= 2500000) {
            region = 3;
        }
        if (budgetMax > 2500000 && budgetMax <= 3400000) {
            region = 4;
        }
        if (budgetMax > 3400000 && budgetMax <= 5000000) {
            region = 5;
        }
        if (budgetMax > 5000000) {
            region = 6;
        }

        if (inArea == 1) {
            if (budgetMax > 0 && budgetMax <= 2100000) {
                region = 1;
            }
            if (budgetMax > 2100000 && budgetMax <= 3250000) {
                region = 2;
            }
            if (budgetMax > 3250000 && budgetMax <= 4860000) {
                region = 3;
            }
            if (budgetMax > 4860000 && budgetMax <= 7700000) {
                region = 4;
            }
            if (budgetMax > 7700000) {
                region = 5;
            }
        }

        if (inArea == 2) {
            if (budgetMax > 0 && budgetMax <= 2570000) {
                region = 1;
            }
            if (budgetMax > 2570000 && budgetMax <= 3700000) {
                region = 2;
            }
            if (budgetMax > 3700000 && budgetMax <= 5200000) {
                region = 3;
            }
            if (budgetMax > 5200000) {
                region = 4;
            }
        }

        if (inArea == 3) {
            if (budgetMax > 0 && budgetMax <= 2200000) {
                region = 1;
            }
            if (budgetMax > 2200000 && budgetMax <= 3400000) {
                region = 2;
            }
            if (budgetMax > 3400000) {
                region = 3;
            }
        }
        if (inArea == 4) {
            if (budgetMax > 0 && budgetMax <= 2600000) {
                region = 1;
            }
            if (budgetMax > 2600000 && budgetMax <= 4500000) {
                region = 2;
            }
            if (budgetMax > 4500000) {
                region = 3;
            }
        }
        if (inArea == 8) { // city is xi  an
            if (budgetMax > 0 && budgetMax <= 1500000) {
                region = 1;
            }
            if (budgetMax > 1500000 && budgetMax <= 2300000) {
                region = 2;
            }
            if (budgetMax > 2300000 && budgetMax <= 3200000) {
                region = 3;
            }
            if (budgetMax > 3200000) {
                region = 4;
            }
        }


        if (inArea == 9) { // city is meishan
            if (budgetMax > 0 && budgetMax <= 2100000) {
                region = 1;
            }
            if (budgetMax > 2100000 && budgetMax <= 3000000) {
                region = 2;
            }
            if (budgetMax > 3000000) {
                region = 3;
            }
        }

        if (inArea == 10) { // city is jj_leshan
            if (budgetMax > 0 && budgetMax <= 2100000) {
                region = 1;
            }
            if (budgetMax > 2100000 && budgetMax <= 3300000) {
                region = 2;
            }
            if (budgetMax > 3300000) {
                region = 3;
            }
        }
        if (inArea == 11) { // city is jj_nanchong
            if (budgetMax > 0 && budgetMax <= 2100000) {
                region = 1;
            }
            if (budgetMax > 2100000 && budgetMax <= 3400000) {
                region = 2;
            }
            if (budgetMax > 3400000 && budgetMax <= 5900000) {
                region = 3;
            }
            if (budgetMax > 5900000) {
                region = 4;
            }
        }
        return region;
    }


    /**
     * section_yn        预算范围:
     * 1                 (0 , 21000]
     * 2                 (21000 , 32500]
     * 3                 (32500 , 48600]
     * 4                 (48600 , 77000]
     * 5                 (77000 , ∞]
     */
    public static List<PlannerQueryInfoVO> processHotelRecomWorker(int budgetMax,
                                                                   String hotel, String provinceName, String cityName,
                                                                   String hotel_id,
                                                                   List<WorkerQueryInfoVO> workersList,
                                                                   List<PlannerQueryInfoVO> resultList,
                                                                   List<PlannerRecomRankVO> plannerList, Map<String,
            List<PlannerRecomRankVO>> recomRankMap, String[] tagList, int responNum,
                                                                   String weddate, String hotelId, String province, Integer inArea) {
//        int region = 0;
//        if (budgetMax > 0 && budgetMax <= 1200000) {
//            region = 1;
//        }
//        if (budgetMax > 1200000 && budgetMax <= 1800000) {
//            region = 2;
//        }
//        if (budgetMax > 1800000 && budgetMax <= 2500000) {
//            region = 3;
//        }
//        if (budgetMax > 2500000 && budgetMax <= 3400000) {
//            region = 4;
//        }
//        if (budgetMax > 3400000 && budgetMax <= 5000000) {
//            region = 5;
//        }
//        if (budgetMax > 5000000) {
//            region = 6;
//        }
//
//        if (inArea == 1) {
//            if (budgetMax > 0 && budgetMax <= 2100000) {
//                region = 1;
//            }
//            if (budgetMax > 2100000 && budgetMax <= 3250000) {
//                region = 2;
//            }
//            if (budgetMax > 3250000 && budgetMax <= 4860000) {
//                region = 3;
//            }
//            if (budgetMax > 4860000 && budgetMax <= 7700000) {
//                region = 4;
//            }
//            if (budgetMax > 7700000) {
//                region = 5;
//            }
//        }
//
//        if (inArea == 2) {
//            if (budgetMax > 0 && budgetMax <= 2570000) {
//                region = 1;
//            }
//            if (budgetMax > 2570000 && budgetMax <= 3700000) {
//                region = 2;
//            }
//            if (budgetMax > 3700000 && budgetMax <= 5200000) {
//                region = 3;
//            }
//            if (budgetMax > 5200000) {
//                region = 4;
//            }
//        }
//
//        if (inArea == 3) {
//            if (budgetMax > 0 && budgetMax <= 2200000) {
//                region = 1;
//            }
//            if (budgetMax > 2200000 && budgetMax <= 3400000) {
//                region = 2;
//            }
//            if (budgetMax > 3400000) {
//                region = 3;
//            }
//        }
//        if (inArea == 4) {
//            if (budgetMax > 0 && budgetMax <= 2600000) {
//                region = 1;
//            }
//            if (budgetMax > 2600000 && budgetMax <= 4500000) {
//                region = 2;
//            }
//            if (budgetMax > 4500000) {
//                region = 3;
//            }
//        }

        int region = getSectionByMarketBudget(budgetMax, inArea);

        List<PlannerQueryInfoVO> resultList1 = new ArrayList<>();
        List<HotelPlannerRecomRankVO> hotelPlannerList = new ArrayList<>();
        if (region != 0) {
            hotelPlannerList = getHotelSectionPlanner(inArea, region, hotel_id, weddate);
            //@TODO over.
//            if (hotelId.equals("1fa69245-c5bc-4107-9e06-73ebbe0879c0") &&
//                    hotel.equals("世外桃源酒店") && (region == 1 || region == 2)) {
//                hotelPlannerList = Result2Vo.getPlannerRecList(weddate, totalBudget, hotelId, 20000, hotel, String.valueOf(region));
//            } else {
//            if (inArea == 0) {
//                ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_low_budget_hotel", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                Iterator<Result> it = lowBudgetScanner.iterator();
//                while (it.hasNext()) {
//                    HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
//                    hotelPlannerList.add(vo);
//                }
//                if (hotelPlannerList.isEmpty()) {
//                    lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_low_budget_hotel_stream", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                    it = lowBudgetScanner.iterator();
//                    while (it.hasNext()) {
//                        HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
//                        hotelPlannerList.add(vo);
//                    }
//                }
//            } else {
//                ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_low_budget_hotel_area_score", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                Iterator<Result> it = lowBudgetScanner.iterator();
//                while (it.hasNext()) {
//                    HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerAreaScoreVO(it.next());
//                    hotelPlannerList.add(vo);
//                }
//                if (hotelPlannerList.isEmpty()) {
//                    lowBudgetScanner = HBaseUtil.queryRowsWithKeys("tb_low_budget_hotel_area_score_stream", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                    it = lowBudgetScanner.iterator();
//                    while (it.hasNext()) {
//                        HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
//                        hotelPlannerList.add(vo);
//                    }
//                }
//            }

//            }
//            if (!sectionList.contains(1)) {
//                List<HotelPlannerRecomRankVO> plannerRecList = Result2Vo.getPlannerRecList(weddate, 12000, hotelId, 20000, hotel, String.valueOf(region));
//                for (HotelPlannerRecomRankVO hprr : plannerRecList) {
//                    hotelPlannerList.add(hprr);
//                }
//            }
//            if (!sectionList.contains(2)) {
//                List<HotelPlannerRecomRankVO> plannerRecList = Result2Vo.getPlannerRecList(weddate, 18000, hotelId, 20000, hotel, String.valueOf(region));
//                for (HotelPlannerRecomRankVO hprr : plannerRecList) {
//                    hotelPlannerList.add(hprr);
//                }
//            }
//            if (!sectionList.contains(3)) {
//                List<HotelPlannerRecomRankVO> plannerRecList = Result2Vo.getPlannerRecList(weddate, 25000, hotelId, 20000, hotel, String.valueOf(region));
//                for (HotelPlannerRecomRankVO hprr : plannerRecList) {
//                    hotelPlannerList.add(hprr);
//                }
//            }
//            if (!sectionList.contains(4)) {
//                List<HotelPlannerRecomRankVO> plannerRecList = Result2Vo.getPlannerRecList(weddate, 34000, hotelId, 20000, hotel, String.valueOf(region));
//                for (HotelPlannerRecomRankVO hprr : plannerRecList) {
//                    hotelPlannerList.add(hprr);
//                }
//            }
//            if (!sectionList.contains(5)) {
//                List<HotelPlannerRecomRankVO> plannerRecList = Result2Vo.getPlannerRecList(weddate, 50000, hotelId, 20000, hotel, String.valueOf(region));
//                for (HotelPlannerRecomRankVO hprr : plannerRecList) {
//                    hotelPlannerList.add(hprr);
//                }
        }
//            List<HotelPlannerRecomRankVO> hotelPlannerList = plannerRecomRankControllerService.
//                    queryHotelPlannerRecomRank(null, region, hotel, provinceName, cityName, weddate, hotelId);


//        if (!isNull(hotelPlannerList) && hotelPlannerList.size() > 0) {
        if (!isNull(hotelPlannerList) && hotelPlannerList.size() > 0) {
            if (!isNull(workersList) && workersList.size() > 0) {
                Map<String, WorkerQueryInfoVO> workerMap = workersList.stream()
                        .collect(Collectors.toMap(WorkerQueryInfoVO::getId, bs -> {
                            return bs;
                        }));

                Gson gson = new Gson();
                ListSortUtil<HotelPlannerRecomRankVO> sortList = new ListSortUtil<HotelPlannerRecomRankVO>();
                sortList.sortByMethod(hotelPlannerList, "getSot", true);

                logger.info("_____  province is " + province + " hotelPlannerList  sort msg is  " + gson.toJson(hotelPlannerList));

                for (HotelPlannerRecomRankVO hotelRecom : hotelPlannerList) {
                    WorkerQueryInfoVO worker = workerMap.get(hotelRecom.getWorkerId());
                    if (null != worker && province.equals(worker.getProvinceName())) {
                        List<PlannerRecomRankVO> plannerRecomList = recomRankMap.get(worker.getId());
                        List<String> planneTagList = new ArrayList<>();
                        if (null != plannerRecomList && !plannerRecomList.isEmpty()) {
                            PlannerRecomRankVO vo = plannerRecomList.get(0);
                            boolean flag = false;
                            if ("v2".equals(vo.getVersion())) {
//                                flag = veritfyWorkerVersion2(tagList, wedding.getBudgetMin(), wedding.getBudgetMax(), plannerRecomList);
                                boolean tagFlag = veritfyTagV2(tagList, vo.getTags());
                                if (tagFlag) {
                                    PlannerRecomRankVO temp = getSectionVO(region, plannerRecomList);
                                    if (null != temp) {
                                        vo = temp;
                                        flag = true;
                                    }
                                }
                                planneTagList = vo.getTags();
                            } else {
                                for (PlannerRecomRankVO rankVO : plannerRecomList) {
                                    planneTagList.add(rankVO.getType());
                                }
                                Map<String, PlannerRecomRankVO> plannerTagMap = plannerRecomList.stream()
                                        .collect(Collectors.toMap(PlannerRecomRankVO::getType, bs -> {
                                            return bs;
                                        }));

                                flag = veritfyWorker(tagList, worker, plannerTagMap, 0,
                                        budgetMax, plannerRecomList, 0);
                            }

                            if (flag) {
//                                PlannerRecomRankVO vo = plannerRecomList.get(0);
                                // 职业人通过筛选
                                PlannerQueryInfoVO info = new PlannerQueryInfoVO();
                                BeanUtils.copyProperties(worker, info);
                                // 推荐信息合并
                                info.setWorkerId(vo.getWorkerId());
                                info.setCaseRate(vo.getCaseRate());
                                info.setReorderRate(vo.getReorderRate());
                                info.setPreSpeScore(vo.getPreSpeScore());
                                info.setAllScoreFinal(vo.getAllScoreFinal());
                                info.setSot(hotelRecom.getSot());
                                info.setScoreFlag1(vo.getScoreFlag1());
                                info.setScoreFlag2(vo.getScoreFlag2());
                                info.setScoreFlag3(vo.getScoreFlag3());
                                info.setScoreFlag4(vo.getScoreFlag4());
                                info.setScoreFlag5(vo.getScoreFlag5());
                                info.setTagList(planneTagList);
                                info.setServiceCity(null);
                                info.setProfile(null);
                                info.setHomePage(null);
                                info.setType(0);
                                info.setHotelScore(hotelRecom.getSot());
                                info.setDistance(hotelRecom.getDistance());
                                //排除已经在结果中的数据
                                if (!JSON.toJSONString(resultList).contains(info.getWorkerId()) &&
                                        !JSON.toJSONString(resultList1).contains(info.getWorkerId())) {
                                    if (responNum != -1) {
                                        if (responNum > resultList1.size()) {
                                            resultList1.add(info);
                                        }
                                    } else {
                                        resultList1.add(info);
                                    }
                                }
//									if(recomType != -1){
//										if(recomType == 0){
//											if(resultList.size() >= 3){
//												break;
//											}
//										}else{
//											if(resultList.size() >= 4){
//												break;
//											}
//										}
//									}
                            }
                        }
                        plannerRecomList = new ArrayList<>();
                    }
                }
            }
        }

        return resultList1;
    }


    public static List<PlannerQueryInfoVO> processHotelRecomWorkerYingJing(List<WorkerQueryInfoVO> workersList, Map<String, Double> workerDis,
                                                                           Map<String, List<PlannerRecomRankVO>> recomRankMap, int responNum) {
        List<PlannerQueryInfoVO> resultList1 = new ArrayList<>();
        for (WorkerQueryInfoVO worker : workersList) {
            PlannerQueryInfoVO info = new PlannerQueryInfoVO();
            BeanUtils.copyProperties(worker, info);
            List<PlannerRecomRankVO> plannerRecomList = recomRankMap.get(worker.getId());
            if (null != plannerRecomList && plannerRecomList.size() > 0) {
                List<String> planneTagList = new ArrayList<>();
                PlannerRecomRankVO vo = plannerRecomList.get(0);
                for (PlannerRecomRankVO rankVO : plannerRecomList) {
                    planneTagList.add(rankVO.getType());
                }

                // 推荐信息合并
                info.setWorkerId(vo.getWorkerId());
                info.setCaseRate(vo.getCaseRate());
                info.setReorderRate(vo.getReorderRate());
                info.setPreSpeScore(vo.getPreSpeScore());
                info.setAllScoreFinal(vo.getAllScoreFinal());
                info.setScoreFlag1(vo.getScoreFlag1());
                info.setScoreFlag2(vo.getScoreFlag2());
                info.setScoreFlag3(vo.getScoreFlag3());
                info.setScoreFlag4(vo.getScoreFlag4());
                info.setScoreFlag5(vo.getScoreFlag5());
                info.setTagList(planneTagList);
                info.setServiceCity(null);
                info.setProfile(null);
                info.setHomePage(null);
                info.setType(0);
//            info.setHotelScore(hotelRecom.getSot());
                double dis = workerDis.containsKey(vo.getWorkerId()) ? workerDis.get(vo.getWorkerId()) : 0d;

                info.setDistance(dis);
                double distance =
                        new BigDecimal(info.getDistance()).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                String distanceStr = "距酒店:" + distance + "km";
                info.setDistanceStr(distanceStr);
                if (resultList1.size() < 6) resultList1.add(info);
                else break;
            }
        }

        return resultList1;
    }


    public static List<PlannerQueryInfoVO> getSmallMaketWorker(String hotel_id, Integer section, String weddate,
                                                               List<PlannerQueryInfoVO> resultList, int responNum,
                                                               Map<String, List<PlannerRecomRankVO>> recomRankMap, int budgetMax) {
        List<PlannerQueryInfoVO> resultList1 = new ArrayList<>();
        Gson gson = new Gson();
        List<HotelPlannerRecomRankVO> hotelPlannerList = getSmallMaketV2(hotel_id, section, weddate);
        logger.info("_____ get Small Maket  hotelPlannerList " + gson.toJson(hotelPlannerList));
        List<WorkerQueryInfoVO> workersList = getWorkerMsg();
        if (!isNull(hotelPlannerList) && hotelPlannerList.size() > 0) {
            if (!isNull(workersList) && workersList.size() > 0) {
                Map<String, WorkerQueryInfoVO> workerMap = workersList.stream()
                        .collect(Collectors.toMap(WorkerQueryInfoVO::getId, bs -> {
                            return bs;
                        }));

//                ListSortUtil<HotelPlannerRecomRankVO> sortList = new ListSortUtil<HotelPlannerRecomRankVO>();
//                sortList.sortByMethod(hotelPlannerList, "getSot", true);

                for (HotelPlannerRecomRankVO hotelRecom : hotelPlannerList) {
                    WorkerQueryInfoVO worker = workerMap.get(hotelRecom.getWorkerId());
//                    if (null != worker && province.equals(worker.getProvinceName())) {
                    if (null == recomRankMap) {
                        List<PlannerRecomRankVO> allPlannerList = getAllWorkerRank(budgetMax, 0);
                        recomRankMap = allPlannerList.stream().collect(Collectors.groupingBy(PlannerRecomRankVO::getWorkerId));
                    }

                    List<PlannerRecomRankVO> plannerRecomList = recomRankMap.get(worker.getId());
                    List<String> planneTagList = new ArrayList<>();
                    if (null != plannerRecomList && !plannerRecomList.isEmpty()) {
                        for (PlannerRecomRankVO rankVO : plannerRecomList) {
                            planneTagList.add(rankVO.getType());
                        }
                        PlannerRecomRankVO vo = plannerRecomList.get(0);
                        // 职业人通过筛选
                        PlannerQueryInfoVO info = new PlannerQueryInfoVO();
                        BeanUtils.copyProperties(worker, info);
                        // 推荐信息合并
                        info.setWorkerId(vo.getWorkerId());
                        info.setCaseRate(vo.getCaseRate());
                        info.setReorderRate(vo.getReorderRate());
                        info.setPreSpeScore(vo.getPreSpeScore());
                        info.setAllScoreFinal(vo.getAllScoreFinal());
                        info.setSot(vo.getSot());
                        info.setScoreFlag1(vo.getScoreFlag1());
                        info.setScoreFlag2(vo.getScoreFlag2());
                        info.setScoreFlag3(vo.getScoreFlag3());
                        info.setScoreFlag4(vo.getScoreFlag4());
                        info.setScoreFlag5(vo.getScoreFlag5());
                        info.setTagList(planneTagList);
                        info.setServiceCity(null);
                        info.setProfile(null);
                        info.setHomePage(null);
                        info.setType(0);
                        info.setHotelScore(hotelRecom.getSot());
                        info.setDistance(hotelRecom.getDistance());
                        //排除已经在结果中的数据
                        if (!JSON.toJSONString(resultList).contains(info.getWorkerId()) &&
                                !JSON.toJSONString(resultList1).contains(info.getWorkerId())) {
                            if (responNum != -1) {
                                if (responNum > resultList1.size()) {
                                    resultList1.add(info);
                                }
                            } else {
                                resultList1.add(info);
                            }
                        }

                    }
                    plannerRecomList = new ArrayList<>();
//                    }
                }
            }
        }

        logger.info("_____  the small market result is " + gson.toJson(resultList1));
        return resultList1;
    }

    public static List<HotelPlannerRecomRankVO> getSmallMaket(String hotel_id, Integer section) {
        List<HotelPlannerRecomRankVO> hotelPlannerList = new ArrayList<>();
        String baseUrl = "http://115.28.210.28:8380/model?hotelid=" + hotel_id + "&section=" + section;
        String r = doGet(baseUrl);
        logger.info("_____ get Small Maket  inArea is " + 5 + "  hotel_id is " + hotel_id + " section is " + section +
                " , the result is " + r);
        try {
            if (null != r && !"".equals(r) && !"[]".equals(r) && !"null".equals(r)) {
                JsonArray ja = new JsonParser().parse(r).getAsJsonArray();
                for (int i = 0; i < ja.size(); i++) {
                    JsonObject jb = ja.get(i).getAsJsonObject();
                    HotelPlannerRecomRankVO vo = new HotelPlannerRecomRankVO();
                    vo.setBaseSot(jb.get("sot").getAsFloat());
                    vo.setWorkerId(jb.get("planner_id").getAsString());
                    vo.setSot(jb.get("sort").getAsFloat());
                    vo.setSection(section);
                    hotelPlannerList.add(vo);
                }
            }
        } catch (Exception e) {
            logger.info("_____ jiexi small market result is error " + e.getMessage());
        }

        logger.info("_____ get Small Maket hotelPlannerList  is " + new Gson().toJson(hotelPlannerList));
        return hotelPlannerList;
    }

    public static List<HotelPlannerRecomRankVO> getSmallMaketV2(String hotel_id, Integer section, String weddate) {
        List<HotelPlannerRecomRankVO> hotelPlannerList = new ArrayList<>();
        String baseUrl = "http://115.28.210.28:8381/model?hotelid=" + hotel_id + "&section=" + section + "&weddate=" + weddate;
        String r = doGet(baseUrl);
        logger.info("_____ get Small Maket  inArea is " + 5 + "  hotel_id is " + hotel_id + " section is " + section +
                " weddate is " + weddate +
                " , the result is " + r);
        try {
            if (null != r && !"".equals(r) && !"[]".equals(r) && !"null".equals(r)) {
                JsonArray ja = new JsonParser().parse(r).getAsJsonArray();
                for (int i = 0; i < ja.size(); i++) {
                    JsonObject jb = ja.get(i).getAsJsonObject();
                    HotelPlannerRecomRankVO vo = new HotelPlannerRecomRankVO();
                    vo.setBaseSot(jb.get("sot").getAsFloat());
                    vo.setWorkerId(jb.get("planner_id").getAsString());
                    vo.setSot(jb.get("sort").getAsFloat());
                    vo.setSection(section);
                    hotelPlannerList.add(vo);
                }
            }
        } catch (Exception e) {
            logger.info("_____ jiexi small market result is error " + e.getMessage());
        }

        logger.info("_____ get Small Maket hotelPlannerList  is " + new Gson().toJson(hotelPlannerList));
        return hotelPlannerList;
    }

    public static String doGet(String httpurl) {
        HttpURLConnection connection = null;
        InputStream is = null;
        BufferedReader br = null;
        String result = null;// 返回结果字符串
        try {
            // 创建远程url连接对象
            URL url = new URL(httpurl);
            // 通过远程url连接对象打开一个连接，强转成httpURLConnection类
            connection = (HttpURLConnection) url.openConnection();
            // 设置连接方式：get
            connection.setRequestMethod("GET");
            // 设置连接主机服务器的超时时间：15000毫秒
            connection.setConnectTimeout(30000);
            // 设置读取远程返回的数据时间：60000毫秒
            connection.setReadTimeout(900000);
            // 发送请求
            connection.connect();
            // 通过connection连接，获取输入流
            if (connection.getResponseCode() == 200) {
                is = connection.getInputStream();
                // 封装输入流is，并指定字符集
                br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                // 存放数据
                StringBuffer sbf = new StringBuffer();
                String temp = null;
                while ((temp = br.readLine()) != null) {
                    sbf.append(temp);
                    sbf.append("\r");
                }
                result = sbf.toString();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭资源
            if (null != br) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            connection.disconnect();// 关闭远程连接
        }

        return result;
    }


    public static List<HotelPlannerRecomRankVO> getHotelSectionPlanner(Integer inArea, int region, String hotel_id, String weddate) {
        List<HotelPlannerRecomRankVO> hotelPlannerList = new ArrayList<>();
        String hotel_id_section = hotel_id + "=" + region;
//        Set<String> smallMaketSet = new HashSet<>();
//        smallMaketSet.add("09f8e3bd-0053-44c0-85ff-3939690ecb09,4");
//        smallMaketSet.add("19b725d8-866f-4433-ac93-d85eabc866b3,3");
//        smallMaketSet.add("e55e194f-007d-4c3c-b162-66a2f5619dbb,3");
//        smallMaketSet.add("af155b48-3149-45af-8625-16c42d5570e3,4");
//        smallMaketSet.add("f8655d30-1153-4622-9a43-0e43e544d7e9,3");
//        smallMaketSet.add("ae670242-b297-405b-9a9f-4f7ddd93a59f,3");
        if (inArea == 5) {
            if (RecommendWeddingPlanner.getSmallMarketMsg(hotel_id_section)) {
//                if (smallMaketSet.contains(hotel_id_section)) {
                hotelPlannerList = getSmallMaketV2(hotel_id, region, weddate);
            }
            return hotelPlannerList;
        }


        String batchTable = "";
        String streamTable = "";
        double minDis = 0;
        double maxDis = 0;
        if (inArea == 0) {
//            batchTable = "rp_tb_low_budget_hotel";
            batchTable = "v2_rp_tb_low_budget_hotel2";
//            streamTable = "rp_tb_low_budget_hotel_stream";
            streamTable = "rp_tb_low_budget_hotel_stream2";
            maxDis = 20000;
        } else if (inArea == 1) {
//            batchTable = "rp_tb_low_budget_hotel_area_score";
//            streamTable = "tb_low_budget_hotel_area_score_stream";
//            batchTable = "tb_hotel_section_score_20_50_batch";
            batchTable = "tb_hotel_section_score_20_50_batch_v2";
            streamTable = "tb_hotel_section_score_20_50_stream";
            minDis = 20000;
            maxDis = 50000;
        } else if (inArea == 2) {
//            batchTable = "rp_tb_prepare_worker_area_score";
//            streamTable = "rp_tb_prepare_worker_area_score_stream";
//            batchTable = "tb_hotel_section_score_50_100_batch";
            batchTable = "tb_hotel_section_score_50_100_batch_v2";
            streamTable = "tb_hotel_section_score_50_100_stream";
            minDis = 50000;
            maxDis = 100000;
        } else if (inArea == 3) {
//            batchTable = "rp_tb_low_budget_hotel_area_score";
//            streamTable = "tb_low_budget_hotel_area_score_stream";
//            batchTable = "tb_hotel_section_score_100_150_batch";
            batchTable = "tb_hotel_section_score_100_150_batch_v2";
            streamTable = "tb_hotel_section_score_100_150_stream";
            minDis = 100000;
            maxDis = 150000;
        } else if (inArea == 4) {
//            batchTable = "rp_tb_low_budget_hotel_area_score";
//            streamTable = "tb_low_budget_hotel_area_score_stream";
//            batchTable = "tb_hotel_section_score_150_more_batch";
            batchTable = "tb_hotel_section_score_150_more_batch_v2";
            streamTable = "tb_hotel_section_score_150_more_stream";
            minDis = 150000;
            maxDis = Double.MAX_VALUE;
        } else if (inArea == 6) {
            batchTable = "teacher_sun_hotel_section_planner";
            streamTable = "teacher_sun_hotel_section_planner";
            minDis = 0;
            maxDis = Double.MAX_VALUE;
        } else if (inArea == 20) {
            batchTable = "rp_tb_hotel_worker_distance_v3";
            streamTable = "rp_tb_hotel_worker_distance_v3";
            minDis = 0;
            maxDis = Double.MAX_VALUE;
            region = 20;
        } else {
            batchTable = "rp_tb_low_budget_hotel_area_score";
            streamTable = "tb_low_budget_hotel_area_score_stream";
            minDis = 0;
            maxDis = Double.MAX_VALUE;
        }

        ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys(batchTable, hotel_id + "=" + region, hotel_id + "=" + region + ">");
        Iterator<Result> it = lowBudgetScanner.iterator();
        while (it.hasNext()) {
            HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
            if (vo.getDistance() > minDis && vo.getDistance() <= maxDis)
                hotelPlannerList.add(vo);
        }
        logger.info("_____  inArea is " + inArea + "  hotelPlannerList  " + batchTable + " is " + hotelPlannerList.size());

        if (hotelPlannerList.isEmpty()) {
            lowBudgetScanner = HBaseUtil.queryRowsWithKeys(streamTable, hotel_id + "=" + region, hotel_id + "=" + region + ">");
            it = lowBudgetScanner.iterator();
            while (it.hasNext()) {
                HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
                if (vo.getDistance() > minDis && vo.getDistance() <= maxDis)
                    hotelPlannerList.add(vo);
            }
            logger.info("_____  inArea is " + inArea + "   hotelPlannerList  " + streamTable + " is " + hotelPlannerList.size());
        }


//        if (inArea == 0) {
//            ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_low_budget_hotel", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//            Iterator<Result> it = lowBudgetScanner.iterator();
//            while (it.hasNext()) {
//                HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
//                hotelPlannerList.add(vo);
//            }
//            logger.info("_____  hotelPlannerList rp_tb_low_budget_hotel " + hotelPlannerList.size());
//
//            if (hotelPlannerList.isEmpty()) {
//                lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_low_budget_hotel_stream", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                it = lowBudgetScanner.iterator();
//                while (it.hasNext()) {
//                    HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
//                    hotelPlannerList.add(vo);
//                }
//                logger.info("_____  hotelPlannerList rp_tb_low_budget_hotel_stream " + hotelPlannerList.size());
//            }
//        } else if (inArea == 2) {
//            ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_prepare_worker_area_score", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//            Iterator<Result> it = lowBudgetScanner.iterator();
//            while (it.hasNext()) {
//                HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerAreaScoreVO(it.next());
//                hotelPlannerList.add(vo);
//            }
//            logger.info("_____  hotelPlannerList rp_tb_prepare_worker_area_score " + hotelPlannerList.size());
//            if (hotelPlannerList.isEmpty()) {
//                lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_prepare_worker_area_score_stream", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                it = lowBudgetScanner.iterator();
//                while (it.hasNext()) {
//                    HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerAreaScoreVO(it.next());
//                    hotelPlannerList.add(vo);
//                }
//                logger.info("_____  hotelPlannerList rp_tb_prepare_worker_area_score_stream " + hotelPlannerList.size());
//            }
//        } else {
//            ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys("rp_tb_low_budget_hotel_area_score", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//            Iterator<Result> it = lowBudgetScanner.iterator();
//            while (it.hasNext()) {
//                HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerAreaScoreVO(it.next());
//                hotelPlannerList.add(vo);
//            }
//            logger.info("_____  hotelPlannerList rp_tb_low_budget_hotel_area_score " + hotelPlannerList.size());
//            if (hotelPlannerList.isEmpty()) {
//                lowBudgetScanner = HBaseUtil.queryRowsWithKeys("tb_low_budget_hotel_area_score_stream", hotel_id + "=" + region, hotel_id + "=" + region + ">");
//                it = lowBudgetScanner.iterator();
//                while (it.hasNext()) {
//                    HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerAreaScoreVO(it.next());
//                    hotelPlannerList.add(vo);
//                }
//                logger.info("_____  hotelPlannerList tb_low_budget_hotel_area_score_stream " + hotelPlannerList.size());
//            }
//        }

        return hotelPlannerList;
    }

    public static List<HotelPlannerRecomRankVO> getHotelSectionPlannerYingJing(Integer inArea, String hotel_id) {
        List<HotelPlannerRecomRankVO> hotelPlannerList = new ArrayList<>();

        String batchTable = "";
        double minDis = 0;
        double maxDis = 0;
        if (inArea == 0) {
            batchTable = "v2_rp_tb_low_budget_hotel2";
            maxDis = 20000;
        }
        ResultScanner lowBudgetScanner = HBaseUtil.queryRowsWithKeys(batchTable, hotel_id, hotel_id + ">");
        Iterator<Result> it = lowBudgetScanner.iterator();
        while (it.hasNext()) {
            HotelPlannerRecomRankVO vo = Result2Vo.getHotelPlannerRecomRankVO(it.next());
            if (vo.getDistance() > minDis && vo.getDistance() <= maxDis)
                hotelPlannerList.add(vo);
        }
        logger.info("_____  inArea is " + inArea + "  hotelPlannerList  " + batchTable + " is " + hotelPlannerList.size());

        return hotelPlannerList;
    }

    public static String getNextRowkey(String rowkey) {
        return rowkey.substring(0, rowkey.length() - 1) + (char) ((int) rowkey.charAt(rowkey.length() - 1) + 1);
    }


    private static boolean veritfyWorker(String[] tagList, WorkerQueryInfoVO worker,
                                         Map<String, PlannerRecomRankVO> plannerTagMap,
                                         int samount, int eamount,
                                         List<PlannerRecomRankVO> plannerRecomList, int amountType) {
        boolean flag = true;
        if (!isNull(tagList) && tagList.length > 0) {
            // 存在标签
            if (flag) {
                for (int i = 0; i < tagList.length; i++) {
                    PlannerRecomRankVO vo = plannerTagMap.get(tagList[i]);
                    if (isNull(vo)) {
                        // 该职业人标签不存在
                        flag = false;
                    } else {
                        if (amountType != 0) {
                            // 判断预算范围内策划师能否接单
                            if (verifyPlannerBudgetNewV1(samount, eamount, vo)) {
                            } else {
                                flag = false;
                            }
                        }
                    }
                }
            }
        } else {
            if (amountType != 0) {
                // 不存在标签
                for (PlannerRecomRankVO vo : plannerRecomList) {
                    // 判断预算范围内策划师能否接单
                    if (verifyPlannerBudgetNewV1(samount, eamount, vo)) {
                    } else {
                        flag = false;
                    }
                }
            }
        }
        return flag;
    }


    private static boolean veritfyWorkerYingJing(String[] tagList, WorkerQueryInfoVO worker,
                                                 Map<String, PlannerRecomRankVO> plannerTagMap,
                                                 int samount, int eamount,
                                                 List<PlannerRecomRankVO> plannerRecomList, int amountType,
                                                 Map<String, List<YingjingPlannerSectionVO>> sectionVOsMap
    ) {
        boolean flag = true;
        if (!isNull(tagList) && tagList.length > 0) {
            // 存在标签
            if (flag) {
                for (int i = 0; i < tagList.length; i++) {
                    PlannerRecomRankVO vo = plannerTagMap.get(tagList[i]);
                    if (isNull(vo)) {
                        // 该职业人标签不存在
                        flag = false;
                    } else {
                        if (amountType != 0) {
                            // 判断预算范围内策划师能否接单
                            if (verifyPlannerBudgetNewV1YingJing(samount, eamount, vo, sectionVOsMap)) {
                            } else {
                                flag = false;
                            }
                        }
                    }
                }
            }
        } else {
            if (amountType != 0) {
                // 不存在标签
                for (PlannerRecomRankVO vo : plannerRecomList) {
                    // 判断预算范围内策划师能否接单
                    if (verifyPlannerBudgetNewV1YingJing(samount, eamount, vo, sectionVOsMap)) {
                    } else {
                        flag = false;
                    }
                }
            }
        }
        return flag;
    }


    private static boolean verifyPlannerBudgetNewV1(int minamount, int maxamount, PlannerRecomRankVO vo) {
        if (maxamount > 0 && maxamount <= 1200000 && vo.getScoreFlag1() == 1) {
            return true;
        }
        if (maxamount > 1200000 && maxamount <= 1800000 && vo.getScoreFlag2() == 1) {
            return true;
        }
        if (maxamount > 1800000 && maxamount <= 2500000 && vo.getScoreFlag3() == 1) {
            return true;
        }
        if (maxamount > 2500000 && maxamount <= 3400000 && vo.getScoreFlag4() == 1) {
            return true;
        }
        if (maxamount > 3400000 && maxamount <= 5000000 && vo.getScoreFlag5() == 1) {
            return true;
        }
        if (maxamount > 5000000 && maxamount <= 5500000 && vo.getScoreFlag6() == 1) {
            return true;
        }
        if (maxamount > 5500000 && maxamount <= 6500000 && vo.getScoreFlag7() == 1) {
            return true;
        }
        if (maxamount > 6500000 && maxamount <= 7500000 && vo.getScoreFlag8() == 1) {
            return true;
        }
        if (maxamount > 7500000 && maxamount <= 9000000 && vo.getScoreFlag9() == 1) {
            return true;
        }
        if (maxamount > 9000000 && maxamount <= 10000000 && vo.getScoreFlag10() == 1) {
            return true;
        }
        if (maxamount > 10000000 && maxamount <= 13000000 && vo.getScoreFlag11() == 1) {
            return true;
        }
        if (maxamount > 13000000 && maxamount <= 20000000 && vo.getScoreFlag12() == 1) {
            return true;
        }
        if (maxamount > 20000000 && vo.getScoreFlag13() == 1) {
            return true;
        }
        return false;
    }


    private static boolean verifyPlannerBudgetNewV1YingJing(int minamount, int maxamount, PlannerRecomRankVO vo,
                                                            Map<String, List<YingjingPlannerSectionVO>> sectionVOsMap) {


        int section = getSectionByMarketBudget(maxamount, 0);

        return null == getSectionVOYingJing(section, vo, sectionVOsMap) ? false : true;

    }


    /**
     * @param resultList          过滤后的推荐结果
     * @param newWeddingRecomList 是否为预约策划师
     * @param workersList         所以符合条件策划师
     * @param recomRankMap        寇老师数据
     * @param tagList             标签数据
     * @param wedding             wedding
     * @param responNum
     * @param hotelPlannerList
     * @return
     */
    private static List<PlannerQueryInfoVO> processReviseRecomWorker(
            List<PlannerQueryInfoVO> resultList,
            List<PlannerRecomRecordVO> newWeddingRecomList,
            List<WorkerQueryInfoVO> workersList, Map<String, List<PlannerRecomRankVO>> recomRankMap,
            String[] tagList, UserWeddingVO wedding, int responNum, List<HotelPlannerRecomRankVO> hotelPlannerList,
            int inArea) {

        List<PlannerQueryInfoVO> resultList1 = new ArrayList<>();
        if (!isNull(workersList) && workersList.size() > 0) {
            for (PlannerRecomRecordVO recom : newWeddingRecomList) {
                for (WorkerQueryInfoVO worker : workersList) {
                    if (recom.getWorkerId().equals(worker.getId())) {
                        List<PlannerRecomRankVO> plannerRecomList = recomRankMap.get(worker.getId());
                        List<String> planneTagList = new ArrayList<>();
                        if (!isNull(plannerRecomList) && plannerRecomList.size() > 0) {
                            PlannerRecomRankVO vo = plannerRecomList.get(0);
                            boolean flag = false;
                            if ("v2".equals(vo.getVersion())) {
//                                flag = veritfyWorkerVersion2(tagList, wedding.getBudgetMin(), wedding.getBudgetMax(), plannerRecomList);
                                boolean tagFlag = veritfyTagV2(tagList, vo.getTags());
                                if (tagFlag) {
                                    int region = getSectionByMarketBudget(wedding.getBudgetMax(), inArea);
                                    PlannerRecomRankVO temp = getSectionVO(region, plannerRecomList);
                                    if (null != temp) {
                                        flag = true;
                                        vo = temp;
                                        planneTagList = vo.getTags();
                                    }
                                }
                            } else {
                                for (PlannerRecomRankVO vo1 : plannerRecomList) {
                                    planneTagList.add(vo1.getType());
                                }
                                Map<String, PlannerRecomRankVO> plannerMap = plannerRecomList.stream()
                                        .collect(Collectors.toMap(PlannerRecomRankVO::getType, bs -> {
                                            return bs;
                                        }));

                                flag = veritfyWorker(tagList, worker, plannerMap, wedding.getBudgetMin(),
                                        wedding.getBudgetMax(), plannerRecomList, 1);
                            }

                            if (flag) {
//                                PlannerRecomRankVO vo = plannerRecomList.get(0);
                                // 职业人通过筛选
                                PlannerQueryInfoVO info = new PlannerQueryInfoVO();
                                BeanUtils.copyProperties(worker, info);
                                // 推荐信息合并
                                info.setWorkerId(vo.getWorkerId());
                                info.setCaseRate(vo.getCaseRate());
                                info.setReorderRate(vo.getReorderRate());
                                info.setPreSpeScore(vo.getPreSpeScore());
                                info.setAllScoreFinal(vo.getAllScoreFinal());
                                info.setSot(vo.getSot());
                                info.setScoreFlag1(vo.getScoreFlag1());
                                info.setScoreFlag2(vo.getScoreFlag2());
                                info.setScoreFlag3(vo.getScoreFlag3());
                                info.setScoreFlag4(vo.getScoreFlag4());
                                info.setScoreFlag5(vo.getScoreFlag5());
                                info.setTagList(planneTagList);
                                info.setType(0);
                                info.setHotelScore(-99);
                                if (!isNull(hotelPlannerList) && hotelPlannerList.size() > 0) {
                                    for (HotelPlannerRecomRankVO hotel : hotelPlannerList) {
                                        if (hotel.getWorkerId().equals(vo.getWorkerId())) {
                                            info.setHotelScore(hotel.getSot());
                                            break;
                                        }
                                    }
                                }
                                //排除已经在结果中的数据
                                if (!JSON.toJSONString(resultList).contains(info.getWorkerId()) &&
                                        !JSON.toJSONString(resultList1).contains(info.getWorkerId())) {
                                    if (responNum > resultList1.size()) {
                                        resultList1.add(info);
                                    }
                                }
//								if(responNum == 0){
//									if(resultList.size() >= 3){
//										break;
//									}
//								}else{
//									if(resultList.size() >= 4){
//										break;
//									}
//								}
                            }
                        }
                    }
                }
            }
        }
        return resultList1;
    }


    public static List<PlannerRecomRecordVO> getRecomPlanner(UserWeddingVO wedding, String workerId) {
        List<PlannerRecomRecordVO> newWeddingRecomList = new ArrayList<>();
        //@TODO
//        UserByCrmVO user = crmUserControllerService.getUserByMsisdn(wedding.getContactsMsisdn());
        UserByCrmVO user = RecommendWeddingPlanner.getUserByMsisdnV2(wedding.getContactsMsisdn());
        if (!isNull(user) && !isNull(user.getId())) {
            List<String> crmUserIds = new ArrayList<>();
            crmUserIds.add(user.getId());
            //查询邀约信息
            UserReserveVO reserve = RecommendWeddingPlanner.getUserReserveByUserId(user.getId());
            if (!isNull(reserve) && !isNull(reserve.getWorkerId())) {
                List<PlannerRecomRecordVO> plannerRecomList = RecommendWeddingPlanner.queryPlannerRecomRecordByCrmUserIds(crmUserIds);
                if (!isNull(plannerRecomList) && plannerRecomList.size() > 0) {
                    String sctime = plannerRecomList.get(0).getCtime();
                    for (PlannerRecomRecordVO rvo : plannerRecomList) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        Date date = null;
                        try {
                            date = df.parse(rvo.getCtime());
                            date.setTime(date.getTime() + 3000);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (date.after(JavaDateUitl.strToDate(sctime, df)) && date.after(JavaDateUitl.strToDate(reserve.getCtime(), df))) {
                            if (!isNull(workerId)) {
                                if (!workerId.equals(rvo.getWorkerId()) && rvo.getWorkerId().equals(reserve.getWorkerId())) {
                                    newWeddingRecomList.add(rvo);
                                }
                            }
                            //2019-05-22 只推荐邀约的策划师
                            else {
                                if (rvo.getWorkerId().equals(reserve.getWorkerId())) {
                                    newWeddingRecomList.add(rvo);
                                }
                            }
                        }
                    }
                }
            }
        }
        return newWeddingRecomList;
    }


    public static List<WorkerQueryInfoVO> getServiceWorker(String weddingDate,
                                                           String cityId, String provinceId,
                                                           String vocationId, int startAmount, int endAmount) {
        long time = System.currentTimeMillis();
        List<WorkerQueryInfoVO> workersList = new ArrayList<>();
        Map<String, UserVO> userMap = new HashMap<>();
        Map<String, List<WorkerServiceVO>> workerServiceMap = new HashMap<>();
        //月接单情况
//		Map<String,List<WorkerWeddingOrderVO>> monthScheduleMap = new HashMap<>();
        Map<String, List<WorkerScheduleVO>> wedMonthWorkerScheduleMap = new HashMap<>();
        Map<String, List<WorkerScheduleVO>> scheduleMap = new HashMap<>();
        //职业人订单详情
        Map<String, List<WorkerServiceOrderVO>> workerServiceOrderMap = new HashMap<>();
        Map<String, List<WorkerWeddingOrderVO>> thisMonthOrderMap = new HashMap<>();
        Map<String, List<WorkerWeddingOrderVO>> weddingdateMonthOrderMap = new HashMap<>();
        //职业人月限单（执行）
        Map<String, WorkerMonthOrderLimitVO> workerOrderLimitMap = new HashMap<>();
        //职业人月限单（下单）
        Map<String, WorkerMonthOrderLimitVO> thisMonthWorkerOrderLimitMap = new HashMap<>();

        //策划师月限单（执行）
        Map<String, PlannerLimitVO> plannerOrderLimitMap = new HashMap<>();
        //策划师月限单（下单）
        Map<String, PlannerLimitVO> thisMonthPlannerOrderLimitMap = new HashMap<>();
        List<String> ids = new ArrayList<>();
        List<String> workerIds = new ArrayList<>();

        //查询该服务地下所有职业人
//        WorkerMixQueryBean bean = new WorkerMixQueryBean();
//        if (!isNull(vocationId)) {
//            bean.setVocationId(vocationId);
//        }
//        bean.setStatus(0);
//        if (!isNull(cityId)) {
//            bean.setServiceCityId(cityId);
//        }
//        if (!isNull(provinceId)) {
//            bean.setProvinceId(provinceId);
//        }
//        bean.setStart(0);
//        bean.setRows(10000000);
//        logger.info("time2: " + (System.currentTimeMillis() - time));
//        List<WorkerVO> allWorkerList = workerMixControllerService.queryWorkerVOListByQuery(bean);
//        List<WorkerVO> allWorkerList = RecommendWeddingPlanner.getAllWorkers(HBaseUtil.getFilterList("0", "策划师"));
        List<WorkerVO> allWorkerList = RecommendWeddingPlanner.getAllWorkers(HBaseUtil.getFilterList("0", null, "d677824c-bae7-11e7-99f0-408d5c0cd580"));
        logger.info("___  one day worker on servers time2: " + (System.currentTimeMillis() - time));

        //职业人对应的用户信息
        if (!isNull(allWorkerList)) {
            for (WorkerVO vo : allWorkerList) {
                if (null != vo.getUserId() && !"".equals(vo.getUserId())) ids.add(vo.getUserId());
                if (null != vo.getId() && !"".equals(vo.getId())) workerIds.add(vo.getId());
            }
            userMap = RecommendWeddingPlanner.getUserVO(ids);
//            userMap = RecommendWeddingPlanner.getUserVOList2Map(ids);
            logger.info("___  one day worker on servers time3: " + (System.currentTimeMillis() - time));
            workerServiceMap = RecommendWeddingPlanner.getWorkerServices(workerIds);
            logger.info("___  one day worker on servers time4: " + (System.currentTimeMillis() - time));
            //当月执行
            weddingdateMonthOrderMap = RecommendWeddingPlanner.getWorkerWeddingOrders(workerIds, weddingDate.substring(0, 6),
                    JavaDateUitl.getNextMonth(weddingDate), "2");
            logger.info("___  one day worker on servers time5: " + (System.currentTimeMillis() - time));
            //本月接单
            thisMonthOrderMap = RecommendWeddingPlanner.getWorkerWeddingOrders(workerIds,
                    JavaDateUitl.thisMonth(), JavaDateUitl.nextMonth(), "1"); //create_time;
            wedMonthWorkerScheduleMap = RecommendWeddingPlanner.getWorkerScheduleDates(workerIds,
                    weddingDate.substring(0, 6), JavaDateUitl.getNextMonth(weddingDate));
            logger.info("___  one day worker on servers time6: " + (System.currentTimeMillis() - time));
//            workerServiceOrderMap = CombineAction.getWorkerServiceOrderMap(workerIds, weddingDate, JavaDateUitl.getNextMonth(weddingDate),
//                    workerServiceMap, weddingdateMonthOrderMap);
            workerOrderLimitMap = RecommendWeddingPlanner.getWorkerMonthOrderLimits(workerIds, weddingDate.substring(0, 4), weddingDate.substring(4, 6));
//            workerOrderLimitMap = RecommendWeddingPlanner.getWorkerMonthOrderLimitsList(workerIds, weddingDate.substring(0, 4), weddingDate.substring(4, 6));
            //本月下单
            thisMonthWorkerOrderLimitMap = RecommendWeddingPlanner.getWorkerMonthOrderLimits(workerIds,
                    JavaDateUitl.thisMonth().substring(0, 4), JavaDateUitl.thisMonth().substring(4, 6));
//                   thisMonthWorkerOrderLimitMap = RecommendWeddingPlanner.getWorkerMonthOrderLimitsList(workerIds,
//                    JavaDateUitl.thisMonth().substring(0, 4), JavaDateUitl.thisMonth().substring(4, 6));
            logger.info("___  one day worker on servers time7: " + (System.currentTimeMillis() - time));
            for (WorkerVO worker : allWorkerList) {
                scheduleMap = CombineAction.getScheduleMap(weddingDate, wedMonthWorkerScheduleMap, worker);

                RecommendWeddingPlanner.getWorkerLocation(worker);

                //校验档期、校验日限单、校验月限单
                WorkerInfoVO info = CombineAction.formatWorkerSchdule(worker, weddingDate, null, userMap,
                        workerOrderLimitMap.get(worker.getId()), weddingdateMonthOrderMap.get(worker.getId()),
                        thisMonthOrderMap.get(worker.getId()), scheduleMap,
                        thisMonthWorkerOrderLimitMap.get(worker.getId()), "all");
                if (null != info && info.getSchedule() > 0) {
                    //校验是否存在服务，不存在服务则排除
                    List<WorkerServiceVO> serviceList = workerServiceMap.get(worker.getId());
                    if (!isNull(serviceList) && serviceList.size() > 0) {
                        //2018-06-15 统筹师只展示部分服务，需要先判断当天的服务
                        WorkerQueryInfoVO vo = new WorkerQueryInfoVO();
                        BeanUtils.copyProperties(info, vo);
                        vo = CombineAction.formatWorkerOrderByMap(vo, wedMonthWorkerScheduleMap.get(worker.getId()),
                                weddingDate, worker, serviceList, workerServiceOrderMap.get(worker.getId()));
                        //校验服务价格
                        int serviceNum = 1;
                        if (startAmount != -100 && endAmount != -100 && startAmount != -1 && endAmount != -1) {
                            serviceNum = formatWorkerServiceByMap(worker, vo.getServiceList(), startAmount, endAmount);
                        } else {
//                            if (!isNull(vo.getServiceList()) && vo.getServiceList().size() > 0) {
                            if (null != vo.getServiceList() && !vo.getServiceList().isEmpty()) {
                                serviceNum = 1;
                            } else {
                                serviceNum = 0;
                            }
                        }
                        if (serviceNum > 0) {
                            workersList.add(vo);
                        }
                    }
                }
            }
        }
        long time2 = System.currentTimeMillis();
        logger.info("___  one day worker on servers speed times : " + (time2 - time));
        return workersList;
    }

    public static String getOneWorkerService(String weddingDate, String worker_id) {
        Gson gson = new Gson();
        List<String> ids = new ArrayList<>();
        List<String> workerIds = new ArrayList<>();
        WorkerVO vo = RecommendWeddingPlanner.getWorkerVOById(worker_id);
        Map result = new HashMap<>();

        //职业人对应的用户信息
        if (null != vo) {
            if (null != vo.getUserId() && !"".equals(vo.getUserId())) ids.add(vo.getUserId());
            if (null != vo.getId() && !"".equals(vo.getId())) workerIds.add(vo.getId());
            Map<String, UserVO> userMap = RecommendWeddingPlanner.getUserVO(ids);
//            Map<String, UserVO> userMap = RecommendWeddingPlanner.getUserVOList2Map(ids);
            Map<String, List<WorkerServiceVO>> workerServiceMap = RecommendWeddingPlanner.getWorkerServices(workerIds);

            //当月执行
            Map<String, List<WorkerWeddingOrderVO>> weddingdateMonthOrderMap = RecommendWeddingPlanner.getWorkerWeddingOrders(workerIds, weddingDate.substring(0, 6),
                    JavaDateUitl.getNextMonth(weddingDate), "2");
            //本月接单
            Map<String, List<WorkerWeddingOrderVO>> thisMonthOrderMap = RecommendWeddingPlanner.getWorkerWeddingOrders(workerIds,
                    JavaDateUitl.thisMonth(), JavaDateUitl.nextMonth(), "1"); //create_time;
            Map<String, List<WorkerScheduleVO>> wedMonthWorkerScheduleMap = RecommendWeddingPlanner.getWorkerScheduleDates(workerIds,
                    weddingDate.substring(0, 6), JavaDateUitl.getNextMonth(weddingDate));


            Map<String, WorkerMonthOrderLimitVO> workerOrderLimitMap = RecommendWeddingPlanner.getWorkerMonthOrderLimits(workerIds, weddingDate.substring(0, 4), weddingDate.substring(4, 6));
            //本月下单
            Map<String, WorkerMonthOrderLimitVO> thisMonthWorkerOrderLimitMap = RecommendWeddingPlanner.getWorkerMonthOrderLimits(workerIds,
                    JavaDateUitl.thisMonth().substring(0, 4), JavaDateUitl.thisMonth().substring(4, 6));

            Map<String, List<WorkerScheduleVO>> scheduleMap = CombineAction.getScheduleMap(weddingDate, wedMonthWorkerScheduleMap, vo);

            result.put("当月执行", weddingdateMonthOrderMap);
            result.put("本月接单", thisMonthOrderMap);
            result.put("档期信息", scheduleMap);
            result.put("婚月限单", workerOrderLimitMap);
            result.put("本月限单", thisMonthWorkerOrderLimitMap);

            RecommendWeddingPlanner.getWorkerLocation(vo);

            //校验档期、校验日限单、校验月限单
            WorkerInfoVO info = CombineAction.formatWorkerSchdule(vo, weddingDate, null, userMap,
                    workerOrderLimitMap.get(vo.getId()), weddingdateMonthOrderMap.get(vo.getId()),
                    thisMonthOrderMap.get(vo.getId()), scheduleMap,
                    thisMonthWorkerOrderLimitMap.get(vo.getId()), "all");
            if (null != info && info.getSchedule() > 0) {
                //校验是否存在服务，不存在服务则排除
                List<WorkerServiceVO> serviceList = workerServiceMap.get(vo.getId());
                if (!isNull(serviceList) && serviceList.size() > 0) {
                    //2018-06-15 统筹师只展示部分服务，需要先判断当天的服务
                    WorkerQueryInfoVO vo1 = new WorkerQueryInfoVO();
                    BeanUtils.copyProperties(info, vo1);
                    vo1 = CombineAction.formatWorkerOrderByMap(vo1, wedMonthWorkerScheduleMap.get(vo.getId()),
                            weddingDate, vo, serviceList, null);

                }
            }
            result.put("worker_info", info);

        }

        return gson.toJson(result);
    }


    public static List<WorkerQueryInfoVO> getWorkerMsg() {
        List<WorkerQueryInfoVO> workersList = new ArrayList<>();
        Map<String, UserVO> userMap = new HashMap<>();
        Map<String, List<WorkerServiceVO>> workerServiceMap = new HashMap<>();
        List<String> ids = new ArrayList<>();
        List<String> workerIds = new ArrayList<>();

        List<WorkerVO> allWorkerList = RecommendWeddingPlanner.getAllWorkers(HBaseUtil.getFilterList("0", null, "d677824c-bae7-11e7-99f0-408d5c0cd580"));

        if (!isNull(allWorkerList)) {
            for (WorkerVO vo : allWorkerList) {
                if (null != vo.getUserId() && !"".equals(vo.getUserId())) ids.add(vo.getUserId());
                if (null != vo.getId() && !"".equals(vo.getId())) workerIds.add(vo.getId());
            }
            userMap = RecommendWeddingPlanner.getUserVO(ids);
//            userMap = RecommendWeddingPlanner.getUserVOList2Map(ids);
            workerServiceMap = RecommendWeddingPlanner.getWorkerServices(workerIds);

            for (WorkerVO worker : allWorkerList) {
                RecommendWeddingPlanner.getWorkerLocation(worker);
                WorkerInfoVO info = new WorkerInfoVO();
                BeanUtils.copyProperties(worker, info);
                UserVO user = userMap.get(worker.getUserId()); // userControllerService.queryUserById(worker.getUserId());
                if (null != user) {
                    info.setAvator(user.getAvator());
                    info.setMsisdn(user.getMsisdn());
                }

                //校验是否存在档期
                info.setCanOrderType(5);
                info.setSchedule(1);
                info.setMonthCanOrder(1); // 可以计算
                //校验是否在服务区域
                info.setCityService(0);

                WorkerQueryInfoVO vo = new WorkerQueryInfoVO();
                BeanUtils.copyProperties(info, vo);
                List<WorkerServiceVO> serviceList = workerServiceMap.get(worker.getId());
                vo.setServiceList(serviceList);
                vo.setMonthOrdered(0);
                vo.setYesterdayOrder(0);
                vo.setTomorrowOrder(0);
                vo.setCanOrder(1);
                vo.setOrders(0);

                workersList.add(vo);
            }
        }
        return workersList;
    }

    public static int formatWorkerServiceByMap(WorkerVO worker,
                                               List<WorkerServiceVO> serviceList, int startAmount, int endAmount) {
        int size = 0;
        for (int i = 0; i < serviceList.size(); i++) {
            WorkerServiceVO vo = serviceList.get(i);
            if (vo.getActivityAmount() >= startAmount && vo.getActivityAmount() <= endAmount) {
                size = size + 1;
            }
        }
        return size;
    }

    public static List<PlannerQueryInfoVO> getNormePlanner(
            List<PlannerQueryInfoVO> resultList,
            List<WorkerQueryInfoVO> workersList,
            Map<String, List<PlannerRecomRankVO>> recomRankMap,
            String[] tagList, int budgetMin, int budgetMax, int inArea) {
        for (WorkerQueryInfoVO worker : workersList) {
            List<PlannerRecomRankVO> plannerRecomList = recomRankMap.get(worker.getId());
            List<String> planneTagList = new ArrayList<>();
            if (!isNull(plannerRecomList) && plannerRecomList.size() > 0) {
                //验证标签、预算
                PlannerRecomRankVO vo = plannerRecomList.get(0);
                boolean flag = false;
                if ("v2".equals(vo.getVersion())) {
//                    flag = veritfyWorkerVersion2(tagList, budgetMin, budgetMax, plannerRecomList);
                    boolean tagFlag = veritfyTagV2(tagList, vo.getTags());
                    if (tagFlag) {
                        int region = getSectionByMarketBudget(budgetMax, inArea);
                        PlannerRecomRankVO temp = getSectionVO(region, plannerRecomList);
                        if (null != temp) {
                            vo = temp;
                            planneTagList = vo.getTags();
                            flag = true;
                        }
                    }
                } else {
                    for (PlannerRecomRankVO vo1 : plannerRecomList) {
                        planneTagList.add(vo1.getType()); //获取策划师所以类型
                    }
                    Map<String, PlannerRecomRankVO> plannerTagMap = plannerRecomList.stream()
                            .collect(Collectors.toMap(PlannerRecomRankVO::getType, bs -> {
                                return bs;
                            }));

                    flag = veritfyWorker(tagList, worker, plannerTagMap, budgetMin,
                            budgetMax, plannerRecomList, 1);
                }

                if (flag) {
//                    PlannerRecomRankVO vo = null;
                    // 职业人通过筛选
                    PlannerQueryInfoVO info = new PlannerQueryInfoVO();
                    BeanUtils.copyProperties(worker, info);
                    // 推荐信息合并
                    info.setWorkerId(vo.getWorkerId());
                    info.setCaseRate(vo.getCaseRate());
                    info.setReorderRate(vo.getReorderRate());
                    info.setPreSpeScore(vo.getPreSpeScore());
                    info.setAllScoreFinal(vo.getAllScoreFinal());
                    info.setSot(vo.getSot());
                    info.setScoreFlag1(vo.getScoreFlag1());
                    info.setScoreFlag2(vo.getScoreFlag2());
                    info.setScoreFlag3(vo.getScoreFlag3());
                    info.setScoreFlag4(vo.getScoreFlag4());
                    info.setScoreFlag5(vo.getScoreFlag5());
                    info.setTagList(planneTagList);
//                    info.setProvinceName(worker.getProvinceName());
                    info.setProvinceName(vo.getProvince());
                    info.setCityName(worker.getCityName());
                    info.setType(0);
                    info.setHotelScore(-99);
                    //排除已经在结果中的数据
                    if (!JSON.toJSONString(resultList).contains(info.getWorkerId())) {
                        resultList.add(info);
                    }

                }
            }
        }
        ListSortUtil<PlannerQueryInfoVO> sortList = new ListSortUtil<PlannerQueryInfoVO>();
        sortList.sortByMethod(resultList, "getSot", true);
        return resultList;
    }


//    public static boolean veritfyWorkerVersion2(String[] tagList,
//                                                int samount, int eamount,
//                                                List<PlannerRecomRankVO> plannerRecomList) {
//        boolean tagFlag = false;
//        boolean moneyFlag = false;
//
//        Gson gson = new Gson();
//        if (null != tagList && tagList.length > 0) {
//            PlannerRecomRankVO tempVo = plannerRecomList.get(0);
//            for (String tag : tagList) {
//                if (null != tempVo.getTags() && gson.toJson(tempVo.getTags()).contains(tag)) {
//                    tagFlag = true;
//                }
//            }
//        } else {
//            tagFlag = true;
//        }
//
//
//        if (null != getSectionVO(samount, eamount, plannerRecomList)) moneyFlag = true;
//
//        return tagFlag && moneyFlag;
//    }
//
//
//    public static boolean veritfyTag(String[] tagList,
//                                     List<PlannerRecomRankVO> plannerRecomList) {
//        boolean tagFlag = false;
//        Gson gson = new Gson();
//        if (null != tagList && tagList.length > 0) {
//            PlannerRecomRankVO tempVo = plannerRecomList.get(0);
//            for (String tag : tagList) {
//                if (null != tempVo.getTags() && gson.toJson(tempVo.getTags()).contains(tag)) {
//                    tagFlag = true;
//                }
//            }
//        } else {
//            tagFlag = true;
//        }
//
//        return tagFlag;
//    }

    public static boolean veritfyTagV2(String[] tagList,
                                       List<String> tags) {
        boolean tagFlag = false;
        if (null != tagList && tagList.length > 0) {
            ArrayList tempTags = new ArrayList();
            for (String tag : tagList) {
                tempTags.add(tag);
            }
//                if (null != tags && gson.toJson(tags).contains(tag)) {
            // compute wedding all tags in planner all tags
            if (null != tags && tags.containsAll(tempTags)) {
                tagFlag = true;
            }
        } else {
            tagFlag = true;
        }
        return tagFlag;
    }


//    public static PlannerRecomRankVO getSectionVO(int samount, int eamount,
//                                                  List<PlannerRecomRankVO> plannerRecomList) {
//        int region = 0;
////        if (samount > 0 && eamount <= 1200000) {
////            region = 1;
////        }
////        if (samount > 1200000 && eamount <= 1800000) {
////            region = 2;
////        }
////        if (samount > 1800000 && eamount <= 2500000) {
////            region = 3;
////        }
////        if (samount > 2500000 && eamount <= 3400000) {
////            region = 4;
////        }
////        if (samount > 3400000 && eamount <= 5000000) {
////            region = 5;
////        }
////        if (samount > 5000000) {
////            region = 6;
////        }
//
//        if (eamount > 0 && eamount <= 1200000) {
//            region = 1;
//        }
//        if (eamount > 1200000 && eamount <= 1800000) {
//            region = 2;
//        }
//        if (eamount > 1800000 && eamount <= 2500000) {
//            region = 3;
//        }
//        if (eamount > 2500000 && eamount <= 3400000) {
//            region = 4;
//        }
//        if (eamount > 3400000 && eamount <= 5000000) {
//            region = 5;
//        }
//        if (eamount > 5000000) {
//            region = 6;
//        }
//
//        Map<String, PlannerRecomRankVO> sectionMap = plannerRecomList.stream()
//                .collect(Collectors.toMap(PlannerRecomRankVO::getSection, bs -> {
//                    return bs;
//                }));
//
//        return sectionMap.get(String.valueOf(region));
//
//    }


    public static PlannerRecomRankVO getSectionVO(int section,
                                                  List<PlannerRecomRankVO> plannerRecomList) {

        Map<String, PlannerRecomRankVO> sectionMap = plannerRecomList.stream()
                .collect(Collectors.toMap(PlannerRecomRankVO::getSection, bs -> {
                    return bs;
                }));

        return sectionMap.get(String.valueOf(section));

    }


    public static PlannerRecomRankVO getSectionVOYingJing(int section,
                                                          PlannerRecomRankVO vo,
                                                          Map<String, List<YingjingPlannerSectionVO>> sectionVOsMap) {

        if (sectionVOsMap.containsKey(vo.getWorkerId())) {
            YingjingPlannerSectionVO sectionVO = sectionVOsMap.get(vo.getWorkerId()).get(0);
            if (null != sectionVO && ((1 == section && sectionVO.getSection1() == 1)
                    || (2 == section && sectionVO.getSection2() == 1)
                    || (3 == section && sectionVO.getSection3() == 1)
                    || (4 == section && sectionVO.getSection4() == 1)
                    || (5 == section && sectionVO.getSection5() == 1)
                    || (6 == section && sectionVO.getSection6() == 1))) {
                return vo;
            }
        }
        return null;

    }

    public static WorkerQueryInfoVO getSectionVOYingJingV2(int section,
                                                           WorkerQueryInfoVO vo,
                                                           Map<String, List<YingjingPlannerSectionVO>> sectionVOsMap) {

        if (sectionVOsMap.containsKey(vo.getId())) {
            YingjingPlannerSectionVO sectionVO = sectionVOsMap.get(vo.getId()).get(0);
            if (null != sectionVO && ((1 == section && sectionVO.getSection1() == 1)
                    || (2 == section && sectionVO.getSection2() == 1)
                    || (3 == section && sectionVO.getSection3() == 1)
                    || (4 == section && sectionVO.getSection4() == 1)
                    || (5 == section && sectionVO.getSection5() == 1)
                    || (6 == section && sectionVO.getSection6() == 1))) {
                return vo;
            }
        }
        return null;

    }

}
